Java Strings
A String is a sequence of characters, so whenever, we need a variable to hold a set of characters (username, password, name, address, sentence, paragraph, etc.), we use a String data type (object). Strings are different from the primitive data types as there is a String class with a collection of methods that allow us to manipulate String data and Strings are actually objects.
One mistake that beginning developers and even seasoned developers make is mistaking an empty (null) String for a ‘space String’. “” is different from ” “. Java has a whitespace Unicode character and a String can be comprised of a space, or a String can include a space as well. Therefore, “I love Java” has 11 characters as opposed to 9 characters as the spaces are included. Figure 1 illustrates this:
