HELP! * GREY=local LOCAL HTML version of Foils prepared 29 January 1996

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

From CPS616 Lectures on Java CPS616 Basic Information Track for Computational Science -- Winter-Spring Semester 96. by Geoffrey C. Fox * Critical Information in IMAGE

This class returns object of class String which reverses order of characters in input object source which is also an instance of class String
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();
    • }
  • }
length, CharAt and toString are methods of class String which is used for fixed character strings
StringBuffer is constructor of class StringBuffer which is used for mutable character strings and has methods append and toString



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