1. Determine whether the addresses are equal. Use: ==
The Object class is the super class of all classes, and the equals method of the Object class directly compares addresses. Source code As follows:
public boolean equals(Object obj) { return this == obj; }
2. Determine whether the values are equal. Use: equals method
equals() method is used to compare a string with a specified object.
Syntax
public boolean equals(Object anObject)
Parameters
anObject -- The object to compare with the string.
Return value
Returns true if the given object is equal to the string; otherwise returns false.
public class Test { public static void main(String args[]) { String Str1 = new String("runoob"); String Str2 = Str1; String Str3 = new String("runoob"); boolean retVal; retVal = Str1.equals( Str2 ); System.out.println("返回值 = " + retVal ); retVal = Str1.equals( Str3 ); System.out.println("返回值 = " + retVal ); } }
The execution result of the above program is:
Return value = true
Return value = true
For more java knowledge please Pay attention to the java basic tutorial column.
The above is the detailed content of Java method to determine whether strings are not equal. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools
