-
Book Overview & Buying
-
Table Of Contents
OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808
By :
Up to now, we've been referring to the String and StringBuilder classes as a “sequence of characters.” This is true. They are implemented using an array of characters. An array is an area of memory on the heap with space for a designated number of elements. A String is implemented as an array with some methods that you might want to use when dealing with characters specifically. A StringBuilder is implemented as an array where the array object is replaced with a new bigger array object when it runs out of space to store all the characters. A big difference is that an array can be of any other Java type. If we didn't want to use a String for some reason, we could use an array of char primitives directly:
char[] letters;
This wouldn't be very convenient because we'd lose all the special properties String gives us, such as writing “Java”. Keep in mind that letters is a reference variable and not a primitive. char is...
Change the font size
Change margin width
Change background colour