About 11,700,000 results
Open links in new tab
  1. java - if statement with integers - Stack Overflow

    Mar 26, 2014 · In Java, a similar trick can be used if you are comparing objects using the .equals() method (not ==), and one of them could be null: if(myString.equals("abc")) may produce a NullPointerException if myString is null.

  2. java - How can i fix this equals on primitive type (int ... - Stack ...

    Oct 15, 2015 · For primitives like int, boolean, char etc, you have to use == getMaximumbooks() returns a primitive type int not an Object. You have to compare it with == or in you case != (not equals) return false; Just use == if you're comparing primitives.

  3. How can I properly compare two Integers in Java?

    Since Java 1.7 you can use Objects.equals: java.util.Objects.equals(oneInteger, anotherInteger); Returns true if the arguments are equal to each other and false otherwise. Consequently, if both arguments are null, true is returned and if exactly one argument is null, false is returned.

  4. Check if Two Integers are Equal or Not in Java - GeeksforGeeks

    Jun 21, 2021 · Checking two integers equal or not in Java is done by various approaches. Example. SecondNumber= 15. SecondNumber= 25. Approach #1: Arithmetic Operator. If two numbers are equal then their subtraction is equal to 0. Approach #2: Comparison Operators. If two numbers are equal then equal operator in if condition returns true, else return false.

  5. Java Integer.equals() – Check if two integer values are equal

    In this Java tutorial, you will learn about Integer.equals() method, and how to use this method to check if two Integer objects are equal in value, with the help of examples. Integer.equals() If both the objects have same integer value, then equals() returns true , else it returns false .

  6. How to Compare Object and int in Java 7? - CodingTechRoom

    Solution: Use `Integer.equals()` the method for value comparison, especially when dealing with potential nulls.

  7. Always use equals() to compare Integer Objects in Java

    Jan 4, 2025 · Comparing Integer objects using == can give inconsistent results. Here’s a guide to understanding Integer; equals() vs ==, and how to use them correctly. Integer is a Wrapper class for...

  8. Java Integer equals Method - Online Tutorials Library

    Learn how to use the equals method in Java Integer class to compare integer values effectively. Understand its functionality with examples.

  9. java - Integer equals method - Stack Overflow

    Dec 20, 2012 · Integer#equals checks if two int values are equal, and not just references. So the actual Integer objects might be different (different references), however be equivalent.

  10. Why Avoid Comparing Integers in Java using == Operator? Integer

    Apr 14, 2025 · This happens because autoboxing uses Integer.valueOf() method to convert Integer to int and since method caches Integer object for range -128 to 127, it returns same Integer object in heap, and that's why == operator return true if you compare two Integer object in the range -128 to 127, but return false afterward, causing a bug.

  11. Some results have been removed
Refresh