Basic HTML version of Foils prepared 17 Nov 97

Foil 21 The String Class

From Java Tutorial, July 1, 1996 CEWES Tutorial, CPS606, JSU Class CSC499 -- July 22-25 1997, Fall 97. by Nancy J. McCracken,Geoffrey C. Fox, Tom Scavo


1 Strings are fixed-length collections of Unicode characters.
2 Usually a string is created from a string literal or by using the constructor on an array of characters:
3 String greeting = "Hello";
4 or
5 char[] bunch = {'H', 'e', 'l', 'l', 'o'};
6 String greeting = new String( bunch );
7 Once created, individual characters of a string cannot be changed in place. The following example uses String methods to create a new string:
8 String test = "Chicken soup with rice";
9 int n = test.indexOf( 'w' );
10 String newtest = test.substring(1,n-1) +
    • "is n" + test.substring(n+5);
  • /* giving "Chicken soup is nice" */

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998