Sorting in java - Comparable and Comparator example

Comparable and Comparator are interfaces used during sorting of Java collections. Where Comparable is used to define default / natural ordering, Comparator is mainly used to define customized ordering. Here java.util.Collections class comes into picture with 2 important methods, sort(List list) and sort(List list,Comparator c). The best place to read about them is Javadoc. /** * Student class implements comparable interface * and applies comparison logic in compareTo method. * This logic is default logic for ordering students....

December 12, 2013 · Dinesh Sawant

Pass by Value in Java

In pass by value mechanism copy of the value is created and passed to method. Any change in value passed is not reflected on actual variable which is used to pass value. Another mechanism is pass by reference. In this mechanism reference is passed to method.So any change in values are reflected on actual variable which is used to pass value.Ok, but there is a catch, reference has a different meaning in java....

November 13, 2013 · Dinesh Sawant

Test CORS

April 1, 2001 · Dinesh Sawant