Programming 1A: (PROG5121)
Programming 1A: (PROG5121)
(PROG5121)
CHARACTERS AND STRINGS
System.out.println(myCharacter);
public static void main(String[] args) { System.out.println("After toLowerCase(), aChar is " + aChar);
if (Character.isUpperCase(aChar)) if (Character.isLetterOrDigit(aChar))
else else
System.out.println(aChar + " is not uppercase"); System.out.println(aChar + " is neither a letter nor a digit");
if (Character.isLowerCase(aChar)) if (Character.isWhitespace(aChar))
else else
}
Continued on the right …
}
STRING DATA PITFALLS
import java.util.Scanner;
anotherName = input.nextLine();
if (aName == anotherName)
else
}
STRING OBJECTS ARE IMMUTABLE
• With these classes we can modify a string without creating a new object of the string.
• StringBuffer is thread-safe whereas StringBuilder is not thread-safe. Therefore, it is faster than a string
buffer. Also, the string concatenation operator internally uses StringBuffer or StringBuilder.
public static void main(String[] args) { public static void main(String[] args) {
addressString = new }
The format() method, which DecimalFormat inherits from NumberFormat, must be invoked by myFormatter - it must
accept a double value as argument and return the formatted number in a string.