The String Class
The String Class
So many programming tasks require the manipulation of String data that Java has a built in String class. String is a class rather than a primitive type so note that the name begins with an upper case S, it is NOT string, it is String. It is a general convention in Java that the names of classes begin with upper case letters. The sequence of letters assigned to an instance of a class are surrounded by double quotes. Thus you can create a String variable thus
String sName = "Hello java";
The String class comes with a whole raft of methods for slicing, dicing and searching Strings which we will come across later in this course.
If you have ever used the C programming language you may have become used to storing Strings as arrays of character primitives. An instance of the Java String class is not the same as an array of char primitives. If you need to perform large amounts of String handling, such as importing and manipulating multiple megabytes of text, Java has a StringBuffer class that offers better performance than the String class.