Page 313 - ComputerScience_Class_11
P. 313
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
retupmoC
Write a program to reverse a string and print the result using the reverse() method in a
Program 29
StringBuffer.
1 class stringReverse
2 {
3 public static void main(String[] args)
4 {
5 StringBuffer st=new StringBuffer("Madam");
6 st.reverse();
7 System.out.println(st);
8 }
9 }
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
madaM
10.4 STRING METHODS UNDER WRAPPER CLASS
Wrapper class provides the mechanism to use the primitive data types such as byte, short, int, long, char and boolean
as objects.
The valueOf(String str) Method
This method is used to convert the string str into a primitive data type using the wrapper class. The syntax is:
<primitive type> <variable>= <Wrapper class>.valueOf(String str);
Let us see the below example:
Write a program to convert a string to an integer and a string to a double using valueOf()
Program 30
method and print the result.
1 class string
2 {
3 public static void main(String[] args)
4 {
Strings 311

