Question: I want to sort the List on name property

And the sort should be in ascending like A, a, B, b ... in java

It would be great if someone helps me in this.

For example

```
package corejava.compare;

import java.util.Comparator;

public class FirstNameSorter implements Comparator<Employee>{

     @Override
     public int compare(Employee o1, Employee o2) {
         return o1.getFirstName().compareTo(o2.getFirstName());
     }
}

```

And I have used this comparator as below:

```
Employee e1 = new Employee(1, "aTestName", "dLastName", 34);
Employee e2 = new Employee(2, "A", "pLastName", 30);
Employee e3 = new Employee(3, "T", "sLastName", 31);
Employee e4 = new Employee(4, "D", "zLastName", 25);
Employee e5 = new Employee(5, "b", "zLastName", 25);

List<Employee> employees = new ArrayList<Employee>();
employees.add(e2);
employees.add(e3);
employees.add(e1);
employees.add(e4);
employees.add(e5);

Collections.sort(employees, new FirstNameSorter());

// Sorted by firstName
System.out.println(employees);

```

then I got the following output:

```
A
D
T
b

```

But, I want the following output:

```
A
b
D
T

```

Answer: 
Like @Zabuza mentioned in a comment, the ordering you want is *almost* case-insensitive alphabetical, but not quite, since you want upper & lowercase characters to be grouped together when they're the same letter.

You can accomplish this by adding simply lower-casing the first names and comparing them, with a separate check to revert to a pure lexicographical ordering if the lower-cased check shows a match:

e.g.

```
public class FirstNameSorter implements Comparator<Employee> {
    @Override
    public int compare(Employee o1, Employee o2) {
        int precheck = o1.getFirstName().toLowerCase().compareTo(o2.getFirstName().toLowerCase());
        return precheck != 0 ? precheck : o1.getFirstName().compareTo(o2.getFirstName());
    }
}

```
Maybe this works for you:

```
public class Main {
    public static void main(String[] args) {
        List<String> list = Arrays.asList("A", "D", "a", "b", "B", "T");
        list.sort(comparator());
        System.out.println(list);
    }

    private static Comparator<? super String> comparator() {
        return (Comparator<String>) (leftString, rightString) -> {
            if (leftString.length() == rightString.length()) {
                for (int index = 0; index < leftString.length(); index++) {
                    final String leftChar = leftString.substring(index, index + 1);
                    final String rightChar = rightString.substring(index, index + 1);
                    if (!leftChar.equals(rightChar)) {
                        if (leftChar.toUpperCase().equals(rightChar.toUpperCase())) {
                            if (leftChar.equals(leftChar.toLowerCase()) && 
                                    rightChar.equals(rightChar.toUpperCase())) {
                                return 1;
                            } else {
                                return -1;
                            }
                        } else {
                            return leftChar.toUpperCase()
                                    .compareTo(rightChar.toUpperCase());
                        }
                    }
                }
                return 0;
            } else {
                return (leftString.length() > rightString.length()) ? -1 : +1;
            }
        };
    }
}

```

Output:

```
[A, a, B, b, D, T]

```