0
0
Javaprogramming~15 mins

Common string methods in Java - Cheat Sheet & Quick Revision

Choose your learning style8 modes available
overviewRecall & Review
beginner
What does the length() method do in a Java String?
It returns the number of characters in the string, including spaces and special characters.
touch_appClick to reveal answer
beginner
How does the toUpperCase() method affect a string?
It creates a new string where all letters are converted to uppercase. The original string stays the same.
touch_appClick to reveal answer
intermediate
What is the purpose of the substring(int beginIndex, int endIndex) method?
It extracts a part of the string starting at beginIndex and ending just before endIndex, returning that part as a new string.
touch_appClick to reveal answer
beginner
Explain what equals(String anotherString) does.
It checks if two strings have exactly the same characters in the same order and returns true if they do, otherwise false.
touch_appClick to reveal answer
beginner
What does the trim() method do to a string?
It removes any whitespace at the start and end of the string but does not change spaces inside the string.
touch_appClick to reveal answer
Which method returns the number of characters in a Java string?
Asize()
Blength()
Ccount()
DgetLength()
What does toLowerCase() do to a string?
AConverts all letters to lowercase
BRemoves spaces
CChecks if string is lowercase
DChanges the original string
How do you get a part of a string from index 2 to 5 (exclusive) in Java?
Asubstring(2, 5)
Bslice(2, 5)
Csubstr(2, 5)
Dpart(2, 5)
Which method compares two strings for exact equality?
Acompare()
Bmatch()
Cequals()
D== operator
What does the trim() method remove from a string?
AAll spaces inside the string
BAll whitespace characters everywhere
CTabs inside the string only
DSpaces at the start and end only
Describe five common string methods in Java and what each one does.
Explain how you would extract a substring and compare two strings for equality in Java.