Android Studio collections.sort
时间: 2023-11-02 18:19:07 浏览: 43
`Collections.sort()` is a method in Java which sorts a list of objects in ascending order.
In Android Studio, you can use the `Collections.sort()` method to sort an ArrayList of objects. Here's an example:
```java
// Create an ArrayList of strings
ArrayList<String> myStrings = new ArrayList<>();
myStrings.add("banana");
myStrings.add("apple");
myStrings.add("orange");
// Sort the ArrayList in ascending order
Collections.sort(myStrings);
// Print the sorted ArrayList
System.out.println(myStrings);
```
This code will output `[apple, banana, orange]`, which is the sorted version of the original ArrayList.
You can also use the `Collections.sort()` method with custom objects by implementing the `Comparable` interface and overriding the `compareTo()` method. This allows you to define the sorting logic for your objects.