14.3.2 String Methods length, charAt and getChars

String methods length, charAt and getChars return the length of a String, obtain the character at a specific location in a String and retrieve a set of characters from a String as a char array, respectively. Figure 14.2 demonstrates each of these methods.

 1   // Fig. 14.2: StringMiscellaneous.java 2   // This application demonstrates the length, charAt and getChars 3   // methods of the String class. 4  5   public class StringMiscellaneous 6   { 7      public static void main(String[] args) 8      { 9         String s1 = "hello there";10         char[] charArray = new char[5];11 12         System.out.printf("s1: %s", s1);13 14         // test length method15

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.