Java String equals Example
String class equals method example
String class equals method example. This example shows you how to use equals method.This method Compares this string to the specified object.
Syntax:-equals(Object anObject)
Here is the code:-
/**
* @(#) ContentsEquals.java
*Program that Compares this string to the specified object.
* @Version 01-May-2008
* @author Rose India Team
*/
public class ContentsEquals
{
public static void main(String args[])
{
String str = "Hello World";
String anotherString = "Hello World";
//creating object of anotherString
Object obj = anotherString;
// Compares this string to the specified object,returns true if equals else returns false
System.out.println( str.equals(anotherString) );
}
} |
|