Java String Length

by Dan Bunker


String Length


If you are gong to be doing any kind of string parsing or manipulation, you'll often need to get the length of the string you are working with. This can be done by calling the length() method on the String class. This method is often used in conjunction with the indexOf and substring methods. Another very common use case for the length method is when you are looping through the characters of a string and need to know when you get to the end of the string so you can terminate the loop.