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 can use a reference method

```
public static void main(String[] args) {
    Employee[] employees = new Employee[] { new Employee("John", 25, 3000.0, 9922001),
            new Employee("Ace", 22, 2000.0, 5924001), new Employee("Keith", 35, 4000.0, 3924401) };

    Comparator<Employee> comparingAge = Comparator.comparing(Employee::getAge);
    Comparator<Employee> comparingName = Comparator.comparing(Employee::getName);
    Comparator<Employee> comparingSalary = Comparator.comparing(Employee::getSalary);

    Arrays.sort(employees, comparingAge);
    System.out.println(Arrays.toString(employees));

    Arrays.sort(employees, comparingName);
    System.out.println(Arrays.toString(employees));

    Arrays.sort(employees, comparingSalary);
    System.out.println(Arrays.toString(employees));
}

```

---

you can do too:

```
    sortMe(employees, comparingAge);
    sortMe(employees, comparingName);
    sortMe(employees, comparingSalary);

```

where sortme is :

```
private static void sortMe(Employee[] employees, Comparator<Employee> comparingCriteria) {
    Arrays.sort(employees, comparingCriteria);
}

```
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!!