Sort a set of strings by each string's last character, solution 2
Here's another solution to the same problem, this time I am not using a comparator. Instead, I reverse each element, save it in a new TreeSet which keeps elements in sorted order, then instantiate a new LinkedHashSet which maintains an insertion order, reverse the strings again to the way there were. What I noticed doing this problem is that this solution is faster with larger sample size than solution with comparator. That's a surprising revelation. Also, using StringBuilder to reverse a string is a lot faster than reversing character by character. package com.ervits; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Objects; import java.util.Set; import java.util.TreeSet; /** * * @author Artem * @created Mar 27, 2015 2:15:49 PM * * Project SetSorter * */ public class SetSorterWithReverseString { public static void main(String[] args) { long start = System.curren