Beruflich Dokumente
Kultur Dokumente
• Strings in Java
Results in StringIndexOutofBoundsException
// Creating Strings from byte[] Array
byte[] bytes = {45,65,90,78,23,89};
if(s1.equals(s2)) System.out.println(“Hello”);
else System.out.println(“Hi”); Hello
:String :String
s1 abc s2 abc
s3
6 Object-Oriented Programming Using Java
Comparing Strings : equals()
Method vs == ….
• Example:
String s1 = new String(“abc”);
String s2 = new String(“abc”);
String s3 = s1;
if(s1 == s3) System.out.println(“Hello”);
else System.out.println(“Hi”); Hello
:String :String
s1 abc s2 abc
s3
System.out.println(str);
System.out.println(str);
:String
str = str + " Oriented";
str Object Oriented
System.out.println(str);
:String
str = str + " Oriented";
Object Oriented
System.out.println(str);
String s2 = "abc";
String s3 = "abc";
String s4 = "abc";
}// End of Method
}// End of class StringDemo
String s2 = "abc";
String s3 = "abc";
:String
String s4 = "abc";
}// End of Method s1 abc
}// End of class StringDemo
String s2 = "abc";
String s3 = "abc";
:String
String s4 = "abc";
}// End of Method s1 abc
}// End of class StringDemo
s2
String s2 = "abc";
String s3 = "abc";
:String
String s4 = "abc";
}// End of Method s1 abc
}// End of class StringDemo
s2
s3
String s2 = "abc";
String s3 = "abc";
:String
String s4 = "abc";
}// End of Method s1 abc
}// End of class StringDemo
s2
Only One Object is s3
Created in This Example s4