Search the courses, subjects, tracks, games and features, or jump straight to a page.
5 cards from this section. Quick, good the night before a test.
What method do you use to find the length of a string?
Think of counting characters.
How can you remove spaces from the ends of a string?
It helps clean up the string!
What does the length() method return?
It measures the whole string!
True or False: The trim() method affects spaces inside the string.
Focus on START and END spaces!
Write a program that takes text typed by a user and displays the trimmed and uppercased version of that string. The code editor sends no keyboard input, so store a sample of what a user might type, such as "hello java world" with a few extra spaces at both ends, in a String variable instead of reading it with a Scanner.
Consider combining the methods in sequence.
Given a string sentence = "Learning Java is fun!", write a program that prints its length, its first and last characters, the word "Java" cut out with substring(), and the whole sentence in uppercase.
Work out the index where "Java" starts before you call substring(), and remember that the last character is at length() - 1.
5 more questions in this section. Enroll free to practise them all.
Enroll free