Main Page

Previous Next


You should now be thoroughly familiar with how to create and use arrays. Most people have little trouble dealing with one-dimensional arrays, but arrays of arrays are a bit more tricky so try to practice using these.

You have also acquired a good knowledge of what you can do with String and StringBuffer objects. Most operations with these objects are very straightforward and easy to understand. Being able to decide which methods you should apply to the solution of specific problems is a skill that will come with a bit of practice.

The essential points that we have discussed in this chapter are:

  • You use an array to hold multiple values of the same type, identified through a single variable name.

  • You reference an individual element of an array by using an index value of type int. The index value for an array element is the offset of that element from the first element in the array.

  • An array element can be used in the same way as a single variable of the same type.

  • You can obtain the number of elements in an array by using the length member of the array object.

  • An array element can also contain an array, so you can define arrays of arrays, or arrays of arrays of arrays…

  • A String object stores a fixed character string that cannot be changed. However, you can assign a given String variable to a different String object.

  • You can obtain the number of characters stored in a String object by using the length() method for the object.

  • The String class provides methods for joining, searching, and modifying strings - the modifications being achieved by creating a new String object.

  • A StringBuffer object can store a string of characters that can be modified.

  • You can get the number of characters stored in a StringBuffer object by calling its length() method, and you can find out the current maximum number of characters it can store by using its capacity() method.

  • You can change both the length and the capacity for a StringBuffer object.

  • The StringBuffer class contains a variety of methods for modifying StringBuffer objects.

  • You can create a String object from a StringBuffer object by using the toString() method of the StringBuffer object.

Previous Next
JavaScript Editor Java Tutorials Free JavaScript Editor