Strings: The Objectives of This Chapter Are: To Discuss The String Class and Some of Its Methods
Strings: The Objectives of This Chapter Are: To Discuss The String Class and Some of Its Methods
s “JAVA"
2. Creating String Objects
> System.out.println(str2.indexOf("their"));
-1
3. Common String Methods
– Example:
> String str1 = "Bye";
> String str2 = "Hello";
> System.out.println(str1.compareTo(str2));
-6
> System.out.println(str2.compareTo(str1));
6
3. Common String Methods
– trim()
• Used to remove all the leading and trailing spaces
does not affect whites space in the middle