Key Concepts

Review core concepts you need to learn to master this subject

length() String Method in Java

String str = "Codecademy"; System.out.println(str.length()); // prints 10

In Java, the length() string method returns the total number of characters – the length – of a String.

String Methods
Lesson 1 of 1
  1. 1
    As you may recall, a String, which is widely used in Java, is an object that represents a sequence of characters. It is a great way to store information. Because character strings are so vital to…
  2. 2
    In Java, the length() string method returns the length ⁠— total number of characters ⁠— of a String. Suppose we have a String called str, str.length() would return its length. Take a look at this…
  3. 3
    The concat() method concatenates one string to the end of another string. Concatenation is the operation of joining two strings together. Suppose we have a String called str1 and another String ca…
  4. 4
    With objects, such as Strings, we can’t use the primitive equality operator == to check for equality between two strings. To test equality with strings, we use a built-in method called equals(). F…
  5. 5
    If we want to know the index of the first occurence of a character in a string, we can use the indexOf() method on a string. Remember that the indices in Java start with 0: String letters = “ABCD…
  6. 6
    The charAt() method returns the character located at a String’s specified index. For example: String str = “qwer”; System.out.println(str.charAt(2)); It would output e because that’s what’s at…
  7. 7
    There may be times when we only want a part of a string. In such cases, we may want to extract a substring from a string. The substring() method does exactly that. For example: String line = “…
  8. 8
    There will be times when we have a word in a case other than what we need it in. Luckily, Java has a couple String methods to help us out: - toUpperCase(): returns the string value converted to up…
  9. 9
    Congratulations! 🙌 We have learned some of the string methods that come with the String class: - length() - concat() - indexOf() - charAt() - equals() / equalsIgnoreCase() - substring() - toUppe…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo