2

I have code:

  List<String> list = new ArrayList<String>();
    list.add("10.160.0.100;14/Nov/201107:22:38;/;-;");
    list.add("10.160.0.100;14/Nov/201108:54:31;/;-;");
    list.add("10.160.0.10;16/Nov/201112:56:38;/;-;");

    list.add("10.160.0.100");
    list.add("10.160.0.100");
    list.add("10.160.0.10");


    Collections.sort(list);
    for (String temp : list) {
        System.out.println(temp);
    }

Output is:

10.160.0.10

10.160.0.100

10.160.0.100

10.160.0.100;14/Nov/201107:22:38;/;-;

10.160.0.100;14/Nov/201108:54:31;/;-;

10.160.0.10;16/Nov/201112:56:38;/;-;

Why ? I need this output:

10.160.0.10

10.160.0.100

10.160.0.100

10.160.0.10;16/Nov/201112:56:38;/;-;

10.160.0.100;14/Nov/201107:22:38;/;-;

10.160.0.100;14/Nov/201108:54:31;/;-;

4

1 回答 1

4

Because in ASCII, the ; character has a higher number than the 0 character.

enter image description here

于 2012-11-04T12:51:53.190 回答