// (from the Carter book)
// Example 1A and 1B --> the difference between "length" in arrays
// and "length" in Strings
//
// Example 1A:
//
// In some ways, Strings in Java are much like arrays. For example,
// both arrays and Strings have lengths associated with them. The
// concepts are NOT, however, identical. For an array, its length
// is a PROPERTY: the array called "a" has a length property given
// as "a.length". On the other hand, the length of a String object
// is given by the "instance" METHOD called "length" (in the String
// class) that returns the number of characters in its implicit object:
// the String "s" has a value given by the String method "s.length()".
//
// Example 1B:
//
// If we had made the following declaration:
public class StringMethodsExample1AandB
{
public static void main (String[] args)
{
String s = "Sergiy";
// then the statement:
System.out.println (s.length ());
// would print out the value 6
} // main method
} // StringMethodsExample1AandB class
No comments:
Post a Comment