Question: public class StringCompare { public static void main(String[] args) { int i; String s1 = new String(Test); String s2 = new String(Test); String [] a

public class StringCompare { 
 public static void main(String[] args) { int i; 
 String s1 = new String("Test"); String s2 = new String("Test"); String [] a = {s1, "test", "TEST", "TeSt"}; if (s1 == s2) System.out.println("Same"); for (i = 1; i < 3; i ++) 
 if (s2.equals(a[i-1])) s2 = s2 + " same as " + a[i-1]; 
 System.out.println(s2); } 

}

Can someone explain why this code prints what it prints? Please, explain how each line works. Thank you!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!