How to to make asList and forEach and work?

I am having trouble with making part of my code to work. The error says "Cannot resolve symbol ‘asList’ and "Cannot resolve symbol ‘info’"

One solution I found was to put this code in

public static void main(String[] args) {

and it would work, but I do not know why that is the case.


import org.apache.logging.log4j.LogManager; 
import org.apache.logging.log4j.Logger;

import java.util.Arrays;

public class PrintRanks {
    private static Logger logger = LogManager.getLogger(Runner.class.getName());
    String ranks[] = {"General", "Colonel", "General", "IntelligenceTeam", "Lieutenant", "Major", "Doctor",
            "Nurse", "Operator", "Sergeant", "Soldiers"};
    Arrays.asList(ranks).forEach((ranks) ->; 

>Solution :

Your statement should be inside a method.


public void display(){
   Arrays.asList(this.ranks).forEach((ranks) ->

And then you can call this method (may-be inside the main method?)

Leave a Reply