fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. int arr[]={1,2,9,98,10};
  14. ArrayList<Integer> lst = new ArrayList<Integer>();
  15. for(int i=0;i<arr.length;i++)
  16. lst.add(arr[i]);
  17.  
  18. Collections.sort(lst,new Comparator<Integer>(){
  19. @Override
  20. public int compare(Integer x,Integer y) {
  21.  
  22. // first append Y at the end of X
  23. String XY=x +""+ y;
  24.  
  25. // then append X at the end of Y
  26. String YX=y +""+ x;
  27.  
  28. // Now see which of the two formed numbers
  29. // is greater
  30. return XY.compareTo(YX) > 0 ? -1:1;
  31. }
  32. });
  33. for(int i=0;i<lst.size();i++){
  34. System.out.print(lst.get(i));
  35. }
  36. }
  37. }
Success #stdin #stdout 0.06s 2184192KB
stdin
Standard input is empty
stdout
9982110