Java Reference
In-Depth Information
System.out.println ("compare reference variables = "
+ (englishCaps == temp));
...
compare reference variables = true
// Convert temp to lowercase.
// Compare temp to englishLower using the String method
// equals().
temp = englishCaps.toLowerCase ();
System.out.println ("equals = " +
englishLower.equals (temp));
// Then compare the two String reference variables.
// The result of this comparison is difficult to predict, but
// will normally be false.
System.out.println ("compare reference variables = "
+ (englishLower == temp));
...
equals = true
compare reference variables = false
3. Save these modifications as a text file, and then compile the class in the
DOS command window:
➔ javac HelloWorld.java
Hello World!
Some Text
Some Text
length() = 28
length() = 26
indexOf(M) = 12
charAt(12) = M
substring(12, 17) = MNOPQ
englishLower = abcdefghijklmnopqrstuvwxyz
compareTo = -32
equalsIgnoreCase = true
compareTo = 0
equals = true
compare reference variables = true
equals = true
compare reference variables = false
Examine the various string methods you've used and the results they have
returned. Do they make sense to you? Experiment with some other string
methods on your own (perhaps the replace() method).
Search WWH ::




Custom Search