Question: In Android, I'd like to print fast changing text (>10 Hz) on the smartphone screen instead of into the log file. How should I change the following code?

```
public void onSensorChanged(SensorEvent event) { 
    System.out.println(event.values[0] );  
}

```

Answer: 
You are missing a bit the definition of the of your method:

```
public static <T, U extends Comparable<? super U>> void sortEmpoyeeByCriteria(Function<? super T, ? extends U> byCriteria) {
        Comparator<T> c = Comparator.comparing(byCriteria);
}

```

You should also pass the `List` to that method that you want to sort in this case.

But then why not use `Collections.sort` in this case and pass the `List` and the `Comparator` in the form (for example):

```
Collections.sort(yourList, Comparator.comparing(Employee::getXXX))

```

**EDIT**
You could declare it like this:

```
public static <T, U extends Comparable<? super U>> void sortEmpoyeeByCriteria(
            List<T> list,
            Function<? super T, ? extends U> byCriteria) {
        Comparator<? super T> c = Comparator.comparing(byCriteria);
        list.sort(c);
}

```
Tried lambda approach in Comparator.comparing()

```
class Employee {

  String name;
  int age;
  double salary;
  long mobile;

public Employee(String name, int age, double salary, long mobile) {
    this.name = name;
    this.age = age;
    this.salary = salary;
    this.mobile = mobile;
}

public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public int getAge() {
    return age;
}
public void setAge(int age) {
    this.age = age;
}
public double getSalary() {
    return salary;
}
public void setSalary(double salary) {
    this.salary = salary;
}
public long getMobile() {
    return mobile;
}
public void setMobile(long mobile) {
    this.mobile = mobile;
}

@Override
public String toString() {
    return "Employee [name=" + name + ", age=" + age + ", salary=" + salary + ", mobile=" + mobile + "]";
 }
}

public class MainClass
 {
    public static List<Employee> getEmployee()
    {
        List<Employee> ob = new ArrayList<>();
        ob.add(new Employee("John", 25, 3000.0, 9922001));
        ob.add(new Employee("Ace", 22, 2000.0, 5924001));
        ob.add(new Employee("Keith", 35, 4000.0, 3924401));
        return ob;
    }

    public static void main(String a[]) {
        List<Employee> ob = getEmployee();

        System.out.println("Sort By Name");
        ob.sort(Comparator.comparing(e -> e.getName()));
        System.out.println(ob);

        System.out.println("Sort By Age");
        ob.sort(Comparator.comparing(e -> e.getAge()));
        System.out.println(ob);         
    }
}

```

**Output:**

```
Sort By Name
[Employee [name=Ace, age=22, salary=2000.0, mobile=5924001], Employee [name=John, age=25, salary=3000.0, mobile=9922001], Employee [name=Keith, age=35, salary=4000.0, mobile=3924401]]
Sort By Age
[Employee [name=Ace, age=22, salary=2000.0, mobile=5924001], Employee [name=John, age=25, salary=3000.0, mobile=9922001], Employee [name=Keith, age=35, salary=4000.0, mobile=3924401]]

```

Hope this help!!