Java Reference
In-Depth Information
System.out.println("sentence.substring(0, 6) = \""
+ sentence.substring(0, 6) + "\"");
System.out.println("sentence.substring(7, 12) = \""
+ sentence.substring(7, 12) + "\"");
System.out.println("sentence.substring(7, 22) = \""
+ sentence.substring(7, 22) + "\"");
3
System.out.println("sentence.substring(4, 10) = \""
+ sentence.substring(4, 10) + "\"");
str1 = sentence.substring(0, 8);
System.out.println("str1 = \"" + str1 + "\"");
str2 = sentence.substring(2, 12);
System.out.println("str2 = \"" + str2 + "\"");
System.out.println("sentence in uppercase = \""
+ sentence.toUpperCase() + "\"");
index = sentence.indexOf("birthday");
str1 = sentence.substring(index, index + 14);
System.out.println("str1 = \"" + str1 + "\"");
System.out.println("sentence.replace('t', 'T') = \""
+ sentence.replace('t', 'T') + "\"");
}
}
Sample Run:
sentence = "Now is the time for the birthday party"
The length of sentence = 38
The character at index 16 in sentence = f
The index of first t in sentence = 7
The index of for in sentence = 16
sentence.substring(0, 6) = "Now is"
sentence.substring(7, 12) = "the t"
sentence.substring(7, 22) = "the time for th"
sentence.substring(4, 10) = "is the"
str1 = "Now is t"
str2 = "w is the t"
sentence in uppercase = "NOW IS THE TIME FOR THE BIRTHDAY PARTY"
str1 = "birthday party"
sentence.replace('t', 'T') = "Now is The Time for The birThday parTy"
Search WWH ::




Custom Search