Java collections sort method for string is not working properly for case sensitive and special characters
You can use the Collator class of Java.
public static void main(String[] args) {
List<String> test = new ArrayList<>(new Test().getTestData());
System.out.println(test);
test.sort(Collator.getInstance(Locale.ENGLISH));
System.out.println(test);
}
Output:-
[AA, Aa, aA, aa, 11, BB, Bb, bb, 12, @!, @@!, 117, 21, !@]
[!@, @!, @@!, 11, 117, 12, 21, aa, aA, Aa, AA, bb, Bb, BB]
You could create a custom comparator for your sorting logics. After this you can use it like this:
Collections.sort(yourArrayList, new YourComparator());