Computer Applications

Predict the output of the following Java program snippet:


String S1 = "Computer World";
String S2 = "COMPUTER WORLD";
String S3 = "Computer world";
String S4 = "computer world";
System.out.println(S1 + " equals "+ S2 + " " + S1.equals(S2)); 
System.out.println(S1 + " equals "+ S3 + " " + S1.equals(S3)); 
System.out.println(S1 + " equals "+ S4 + " " + S1.equals(S4)); 
System.out.println(S1 + " equalsIgnoreCase "+ S4 + " " + S1.equalsIgnoreCase(S4));

Java

Java String Handling

57 Likes

Answer

Computer World equals COMPUTER WORLD false
Computer World equals Computer world false
Computer World equals computer world false
Computer World equalsIgnoreCase computer world true

Working

As the strings S1, S2, S3 and S4 differ in the case of the characters so equals() method will return false but equalsIgnoreCase() method will return true.

Answered By

29 Likes


Related Questions