HELP! * GREY=local LOCAL HTML version of Foils prepared July 10 1996

Foil 124 The String class

From Basic Lectures on Java Language Applets Graphics Networking Trip to China and Icase Tutorial -- July 12-28 and June 10-13 96. by Geoffrey C. Fox * Important Information in IMAGE

Strings are fixed length collections of Unicode characters stored as an instance of the class.
Most commonly, a string is created from a string literal or by using the constructor on an array of characters:
  • String greeting = "Hello";
or
  • char[] bunch = {'H','e','l','l','o'};
  • String greeting = new String(bunch);
Once created, individual characters of a string cannot be changed in place. This example shows using the methods of indexing, catenation (+), and substring to create a new string with one character changed:
  • String test = "Chicken soup with rice";
  • int a = test.indexOf('w');
  • String newtest = substring(1,a-1)+"is n"+substring(a+5);
  • /* getting "Chicken soup is nice" */



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 Tue Feb 18 1997