Starting from Java 8 you can use Stream
:
List<String> sorted = Arrays.asList(
names.stream().sorted(
(s1, s2) -> s1.compareToIgnoreCase(s2)
).toArray(String[]::new)
);
It gets a stream from that ArrayList
, then it sorts it (ignoring the case). After that, the stream is converted to an array which is converted to an ArrayList
.
If you print the result using:
System.out.println(sorted);
you get the following output:
[ananya, Athira, bala, jeena, Karthika, Neethu, Nithin, seetha, sudhin, Swetha, Tony, Vinod]