Skip to content

Instantly share code, notes, and snippets.

@nullset2
Last active August 20, 2017 03:59
Show Gist options
  • Save nullset2/f9d3c655bc581968495ca6f38065eecd to your computer and use it in GitHub Desktop.
Save nullset2/f9d3c655bc581968495ca6f38065eecd to your computer and use it in GitHub Desktop.
ArrangeToGreater.java
import java.util.Arrays;
import java.util.Comparator;
class ArrangeToGreater{
private static Integer[] numbers = {5, 2, 1, 9, 50, 56};
public static void main(String[] args){
Arrays.sort(numbers, new Comparator<Integer>() {
@Override
public int compare(Integer l, Integer r) {
String v1 = l.toString();
String v2 = r.toString();
return (v1 + v2).compareTo(v2 + v1) * -1;
}
} );
String result = "";
for(Integer integer: numbers){
result += integer.toString();
}
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment