How To Sort an Array
You can sort an array using the sort()
method from java.util.Arrays
:
Example
import java.util.Arrays;
public class Main {
public static void main(String[] args ) {
String[] cars = {"Volvo", "BMW", "Tesla", "Ford", "Fiat", "Mazda", "Audi"};
Arrays.sort(cars );
for (String i : cars ) {
System.out .println(i );
}
}
}
|