Java – create inline Comparator example

import java.util.Comparator;

public class Main {
  public static void main(String[] args) {
    Comparator<String> comparator = new Comparator<String>() {
      @Override
      public int compare(String o1, String o2) {
        return Integer.valueOf(o1).compareTo(Integer.valueOf(o2));
      }
    };
    System.out.println(comparator.compare("10", "2")); // Should return positive value as int 10 > int 2
  }
}
OpenJDK 64-Bit Server VM warning: Insufficient space for shared memory file:
   1754
Try using the -Djava.io.tmpdir= option to select an alternate temp location.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments