1

I hope to sort myVideoFile with ASCII descending, so I can get the result newVideoFile.get(0) is "d", newVideoFile.get(1) is "c", newVideoFile.get(2) is "b" and newVideoFile.get(3) is "a".

Is there a simple way to do that in java?

 List<String> myVideoFile=new ArrayList<>();

 myVideoFile.add("a");
 myVideoFile.add("b");
 myVideoFile.add("c");
 myVideoFile.add("d");
rekire
  • 47,260
  • 30
  • 167
  • 264
HelloCW
  • 843
  • 22
  • 125
  • 310

2 Answers2

8

You can try this

Collections.sort(data, Collections.reverseOrder());

Sorts the list in descending order.

PC.
  • 6,870
  • 5
  • 36
  • 71
1

The easiest way is Collections.sort(). you have to enter your list(myVideoFile) and how to sort it(in your case: Collections.reverseOrder()).

So if I got your example right your code should lool like that:

 List<String> myVideoFile=new ArrayList<>();

 myVideoFile.add("a");
 myVideoFile.add("b");
 myVideoFile.add("c");
 myVideoFile.add("d");

 Collections.sort(myVideoFile, Collections.reverseOrder());

You can also easily test it by printing out your string in and forech-statment:

    for(String s : myVideoFile)
    {
        //Java way to print
        System.out.println(s);
        //Android way to print
        Log.i("TEST", s);
    }
Felix Gerber
  • 1,615
  • 3
  • 30
  • 40