Tino APCS

String Translation Methods

Translate Method Sample Syntax
String toLowerCase(); String greeting = "Hi World!";
greeting = greeting.toLowerCase();
// greeting <- "hi world!"
String toUpperCase(); String greeting = "Hi World!";
greeting = greeting.toUpperCase();
// greeting <- "HI WORLD!"
String trim(); String needsTrim = " trim me! ";
needsTrim = needsTrim.trim();
// needsTrim <- "trim me!"
String substring(int beginIndex); String sample = "hamburger!";
// sample <- "burger"
String substring(int begin, int end); String sample = "hamburger!";
// sample <- "urge"

toLowerCase() returns a String with the same characters as the String object, but with all characters converted to lowercase. Notice that in all of the above samples, the String object is placed on the left-hand side of the assignment statement. This is necessary because Strings in Java are immutable. Please see section G for a full explanation of immutable.

toUpperCase() returns a String with the same characters as the String object, but with all characters converted to uppercase.

trim() returns a String with the same characters as the String object, but with the leading and trailing whitespace removed.

substring(int beginIndex) returns the substring of the String object starting from beginIndex through to the end of the String object.

substring(int beginIndex, int endIndex) returns the substring of the String object starting from beginIndex through, but not including, position endIndex of the String object. That is, the new String contains characters numbered beginIndex to endIndex-1 in the original String.

Dark Mode

Outline