String s1= \"Welcome to Java\"; String s2= s1; String s3= new String (\"Welcome
ID: 3635193 • Letter: S
Question
String s1= "Welcome to Java";String s2= s1;
String s3= new String ("Welcome to Java")";
String s4 "Welcome to Java";
What are the results of the following expressions? 24 total
(1) s1==s2
(2)s2==s3
(3)s1.equals(s2)
(4)s2.equals(s3)
(5) s1.compareTo(s2)
(6)s2.compareTo(s3)
(7)s1==s4
(8)s1.charAt(0)
(9)s1.indexOf('j')
(10)s1.indexOf("to")
(11)s1.lastIndexOf('a')
(12)s1.lastIndexOf("o", 15)
(13)s1.length()
(14)s1.substring(5)
(15)s1.substring(5,11)
(16)s1.startsWith("Wel")
(17)s1endsWith("Java")
(18)s1.toLowerCase()
(19)s1.toUpperCase()
(20)" Welcome " .trim()
(21)s1.replace('o','T')
(22)s1.replaceAll("o", "T")
(23)s1.replaceFirst("o", "T")
(24)s1.toCharArray()
Explanation / Answer
1) true 2) false 3) true 4) false 5) true 6) false 7) true 8) W 9) 11 10) 8 11) 14 12) 4 13) 15 14) Welco 15) me to J 16) Welcome to Java 17) Welcome to Java 18) welcome to java 19) WELCOME TO JAVA 20) "Welcome" 21) WelcTme tT Java 22) WelcTme tT Java 23) WelcTme tT Java 24) Welcome to Java