Every programmer knows that a list of arrays is printed neatly, but in the middle of the path has sort()
.
The result of this impression was:
Abacaxi
Banana
Laranja
Manga
I imagined it would print this way:
Banana
Laranja
Manga
Abacaxi
I do not know how sort()
behaves, but from what I can see it prints by following the alphabetical order when it comes to strings ?
public class Test {
public static void main(String[] args) {
List<String> fruits = Arrays.asList("Banana", "Laranja", "Manga", "Abacaxi");
Collections.sort(fruits);
for (String fruit : fruits) {
System.out.println(fruit);
}
}
}