Basic HTML version of Foils prepared May 12 1996

Foil 76 ReverseString Class from Sun Tutorial
The String and StringBuffer Classes

From CRPC Lectures on Java Language Applets Graphics CRPC Annual Meeting Tutorial -- May 14,1996. by Geoffrey C. Fox


1 This class returns object of class String which reverses order of characters in input object source which is also an instance of class String
2 class ReverseString {
  • public static String reverseIt(String source) {
    • int i, len= source.length();
    • StringBuffer dest = new StringBuffer(len);
    • for( i= (len-1); i >=0 ; i--) {
    • dest.append(source.charAt(i));
    • }
    • return dest.toString();
    • }
  • }
3 length, CharAt and toString are methods of class String which is used for fixed character strings
4 StringBuffer is constructor of class StringBuffer which is used for mutable character strings and has methods append and toString

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 Sun Dec 14 1997