I have a class that generates random IP addresses. I need to sort this list, but I need to use my own logic to compare two strings.
I would prefer this to override the compareTo method in the String class and use the Arrays.sort() method, but I don't know if this is possible.
I overridden the compareTo method before, but I always just compared instance variables in one class.
public String[] sort(String[] ips) { String[] arr = ips; Arrays.sort(arr); return arr; }
I know there are other ways to do this, but I think it would be more elegant. Please feel free to let me know if you do not agree. I am trying to learn not only code but also code.
jacky source share