
How to sort string array in Java?

import java.util.Arrays;
public class StringSorting {
public static void main(String[] args) {
String[] sa = new String[] { "d", "e", "a", "c", "g" };
System.out.println("Before sorting: " + Arrays.asList(sa));
Arrays.sort(sa);
System.out.println("After sorting: " + Arrays.asList(sa));
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.