1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/* Java StringBuffer Reverse Example This example shows how to reverse the content of the StringBuffer using reverse method of Java StringBuffer class. */ public class JavaStringBufferReverseExample { public static void main(String[] args) { //create StringBuffer object StringBuffer sb = new StringBuffer("Java StringBuffer Reverse Example"); System.out.println("Original StringBuffer Content : " + sb); //To reverse the content of the StringBuffer use reverse method sb.reverse(); System.out.println("Reversed StringBuffer Content : " + sb); } } /* Output Would be Original StringBuffer Content : Java StringBuffer Reverse Example Reversed StringBuffer Content : elpmaxE esreveR reffuBgnirtS avaJ */ |
I think it would be a foolish question to ask but still i am asking that the “Reverse” function of string buffer reverses the index location of characters.But what if i want the string to be in following form..
“Example Reverse StringBuffer Java” for input string “Java StringBuffer Reverse Example”….
see anonymous
to get the output you desire:
see each word ends with a space.
add a space to the inputed sentence at the end.
start extracting the letters by charAt.
keep concatenating them.
stop when there is a space.
start with the next word.
i can send the whole program, if you leave your email id here.
hope it helped.
regards.
Yogya