Java String Flashcards
It contains a collection of Unicode Characters surrounded by double quotes
String
Used for storing text
String
The length of a string can be found with the Length
property.
String length
Syntax of string length
identifier.length()
Returns the uppercase equivalent of the argument; no change is made if the argument is not a lowercase letter.
String toUpperCase
Syntax of String toUpperCase
identifier.toUpperCase()
Returns the lowercase equivalent of the argument; no change is made if the argument is not an uppercase letter.
String toLowerCase
Method of combining two strings or more than string at once
StringConcatenation
You can access the characters in a string by referring to its index number
inside.
String charAt
Syntax of String charAt
identifier.charAt(index number)
You can also find the index position of a specific character in a string, by using the indexOf() method
String indexOf
It extracts the characters from a string, starting from the specified
character position/ index and returns a new string.
String substring()
Syntax of String substring()
identifier.substring(index)
Contains standard methods for testing the values of characters
Character class
Returns true if the arguement is a digit (0-9) and false otherwise
Character.isDigit()
Returns true if the arguement is a letter and false otherwise
Character.isLetter()
Returns true if the arguement is a letter or digit and false otherwise
Character.isLetterorDigit()
Returns true if the arguement is whitespace and false otherwise
Character.isWhitespace()
Each take a String argument and return true or false if a String object does or does not end or start with the specified argument.
endsWith() & startsWith() method
Allows you to replace all occurrences of some character within a String.
replace() method
The method returns true if the objects have identical contents
equals() method
You can compare one string to another.
compareTo() method
Format a string with as many characters as are needed
%s
Format a string with the specified number of characters, and right justify
%15s
Format string with the specified number of characters, and left justify
%-15s
Format a string with as many numebers as are needed
%d
Format a string with a specified number of integers, will pad with spaces to the left if not enough integers
%15d
Format a string with a specified number of integers, will pad with zeros to the left if not enough integers
%04d
Format string with as many numbers as are needed. Will always give you six decimal places
%f
Format string with as many numbers as are needed. Gives 2 decimal places
%.2f
The whole string occupies 10 characters. If there’s not enough numbers, then spaces are used to the left of the numbers
%10.2f