568 Strings and Characters Chapter 10 45 buffer.deleteCharAt( (Virtual web hosting)
568 Strings and Characters Chapter 10 45 buffer.deleteCharAt( 10 ); // delete 5 in 2.5 46 buffer.delete( 2, 6 ); // delete .333 in 33.333 47 48 output += 49 “nnbuffer after deletes:n” + buffer.toString(); 50 51 JOptionPane.showMessageDialog( null, output, 52 “Demonstrating StringBufferer Inserts and Deletes”, 53 JOptionPane.INFORMATION_MESSAGE ); 54 55 System.exit( 0 ); 56 } 57 58 } // end class StringBufferInsert Fig. 10.16 StringBufferclass insertand deletemethods (part 2 of 2). 10.19 CharacterClass Examples Java provides a number of classes that enable primitive variables to be treated as objects. The classes are Boolean, Character, Double, Float, Byte, Short, Integer and Long. These classes (except Booleanand Character) are derived from Number. These eight classes are known as type wrappers, and they are part of the java.lang package. Objects of these classes can be used anywhere in a program that an Objector a Number is expected. In this section, we present class Character the type-wrapper class for characters. Most Characterclass methods are static, take at least a character argument and perform either a test or a manipulation of the character. This class also contains a constructor that receives a charargument to initialize a Characterobject and several non- static methods. Most of the methods of class Character are presented in the next three examples. For more information on class Character(and all the wrapper classes), see the java.langpackage in the Java API documentation. Figure 10.17 demonstrates some static methods that test characters to determine whether they are a specific character type and the staticmethods that perform case conversions on characters. Each method is used in method buildOutput of class StaticCharMethods. You can enter any character and apply the preceding methods to the character. Note the use of inner classes for the event handling as demonstrated in Chapter 9. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01