Home >Java >JavaBase >How to determine whether long type characters are equal in java

How to determine whether long type characters are equal in java

王林
王林Original
2020-02-05 11:42:515696browse

How to determine whether long type characters are equal in java

You can first obtain the value of the basic type long of the Long object through the .longValue() method and then compare it, but when we use longValue to compare, it is easy to forget that the latter wrapper class calls the longValue method. Therefore, it is best to use equals for comparison, or you can directly use .longValue() for comparison, or directly use the .longValue() method for comparison. Remember not to use == for comparison.

(Recommended learning: java video tutorial)

equals method is as follows:

public boolean equals(Object obj) {  
  if (obj instanceof Long) {
      return value == ((Long)obj).longValue();
  }
  return false;
  }

Recommended related tutorials: java introductory tutorial

The above is the detailed content of How to determine whether long type characters are equal in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn