How does the Java link list loop using the for loop?

Hello, I'm trying to create a for loop that iterates through the linked list For each data, it will be listed separately I want to learn the linked list here, so there is no array suggestion, please Does anyone know how to do it?

Sample output:

>Flight 187 > flight 501

My previous code:

public static LinkedList<String> Flights = new LinkedList<String>();

public flightinfo(){
String[] flightNum = {"187","501"};
        for (String x : flightNum)
        Flights.add(x);

                for (???)


}

Solution

Just use the enhanced for loop, just like using an array:

for(String flight : flights) {
   // do what you like with it
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>