Published on August 12, 2024By DeveloperBreeze
Java: How to Sort a List
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SortExample {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("Banana");
list.add("Apple");
list.add("Orange");
Collections.sort(list);
for (String fruit : list) {
System.out.println(fruit);
}
}
}
Comments
Please log in to leave a comment.