Home » Tip Bank » Java
  • Comment on this Article
Language: Java
Expertise: Intermediate
May 15, 2019
  • facebook
  • twitter
  • in
  • Email

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

Comparing Two Integers

Before Java 7, this task required a comparator and the compareTo() method. But, beginning with Java 7, is advisable to rely on Integer.compare(), which is not exposed to overflow risks of compareTo():

// replace x and y with two ints
int result = Integer.compare(x, y);
Octavia Anghel
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
htmlandcssbook.com
javascriptweekly.com