StringNewOpr

StringNewOpr - + "same string.");...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//The substring method / public class StringNewOpr { public static void main (String[] args) { String sentence; String str1; String str2; sentence = "hello"; //Line 1 str1 = sentence; str2 = new String("hello"); if (sentence == str1) System.out.println("senetnce and str1 point to the " + "same string."); else System.out.println("senetnce and str1 do not point to the " + "same string."); if (sentence == str2) System.out.println("senetnce and str2 points to the " + "same string."); else System.out.println("senetnce and str2 do not point to the "
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: + "same string."); if (str1 == str2) System.out.println("str1 and str2 points to the " + "same string."); else System.out.println("str1 and str2 do not point to the " + "same string."); System.out.println(sentence.hashCode()); System.out.println(str1.hashCode()); System.out.println(str2.hashCode()); if (sentence.equals(str2)) System.out.println("Strings senetnce and str2 are the same."); else System.out.println("Strings senetnce and str2 are not the same."); } }...
View Full Document

Ask a homework question - tutors are online