Monday, 5 October 2015

String Buffer class is mutable

/**
 *
 */
import java.io.*;
/**
 * @author U0123154
 *
 */
public class Stringbuffer {

/**
* @param args
*/
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
System.out.println("The hashCode of the string buffer is " +sb.hashCode());
System.out.println("Enter a string");
String sb1 = br.readLine();
sb = sb.append(sb1);
System.out.println("The hashCode of the string buffer is " +sb.hashCode());
System.out.println("The value is  "+sb);
sb = sb.reverse();
System.out.println("The hashCode of the string buffer is " +sb.hashCode());
System.out.println("The value after reversing "+sb);
}
}



Output:-
The hashCode of the string buffer is 366712642
Enter a string
Apple is good for health
The hashCode of the string buffer is 366712642
The value is  Apple is good for health
The hashCode of the string buffer is 366712642
The value after reversing htlaeh rof doog si elppA

No comments:

Post a Comment