4
Every programmer know that a list of arrays are printed in an orderly way, but in the middle of the way sort()
.
The result of the impression was this:
Abacaxi
Banana
Laranja
Manga
I thought it would print that way:
Banana
Laranja
Manga
Abacaxi
I don’t know how the sort()
behaves, but from what I’m seeing he prints 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);
}
}
}
Explain why you think this should be the result, it doesn’t make any sense what you are asking. You want to know what the function
sort()
does? Is that it? If it is, I could not ask more simply?– Maniero
@Maniero I just wanted to know why he printed so Pineapple Banana Orange Mango instead of so Banana Orange Mango Pineapple . in fact I don’t know how Sort behaves.
– wladyband