0% found this document useful (0 votes)
50 views1 page

Problem Description:: Stringcompareemp String String String Object

free

Uploaded by

dasre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views1 page

Problem Description:: Stringcompareemp String String String Object

free

Uploaded by

dasre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Java Examples - Comparing two strings

1 of 1

http://www.tutorialspoint.com/javaexamples/string_compare.htm

http://www.tutorialspoint.com/cgi-bin/printpage.cgi

Copyright tutorialspoint.com

Problem Description:
How to compare two strings ?

Solution:
Following example compares two strings by using str compareTo
, str compareToIgnoreCase
and str compareTo
of string class and returns the ascii difference of first odd characters of
compared strings .
public class StringCompareEmp{
public static void main(String args[]){
String str = "Hello World";
String anotherString = "hello world";
Object objStr = str;
System.out.println( str.compareTo(anotherString) );
System.out.println( str.compareToIgnoreCase(anotherString) );
System.out.println( str.compareTo(objStr.toString()));
}
}

Result:
The above code sample will produce the following result.
-32
0
0

21-Jun-16 2:40 PM

You might also like