The String Class

Premium Content - Free Preview

You've already used some Java Classes - Arrays and Strings. These classes are very basic, so all Java code has built-in access to them. As covered before, you can create Strings with the following syntax:

String name = "jim";

This is a shortcut Java provides since Strings are so common: they can be handled like primitive data types. Strings can also be created like other Objects are, with a new keyword and ():

String name = new String("jim");  //equivalent to previous code

You never need to use the above code form, but it demonstrates that Strings are real Objects.

The String Class
All Strings are instances of the Java String Class. This means that every String instance will have access to all of the methods of the String Class. For example, you can get the length of any Java String with the length() method:

End of Free Content Preview. Please Sign in or Sign up to buy premium content.


  • public Note(String bericht)
    //complete this accessor method
    public String getContent()
    {return content;
    public int noteLength(){
        return content.length();
Contact Us
Sign in or email us at [email protected]