Can anyone tell me how to write a Java program to reverse a given sentence?
For example, if the input is:
\"This is an interview question\"
a every boring bit of java:
List l = new ArrayList(Arrays.asList("this is an interview question".split("\\s")));
Collections.reverse(l);
StringBuffer b = new StringBuffer();
for( String s : l ){
b.append(s).append(' ');
}
b.toString().trim();
in groovy it's a little bit more readable:
"this is an interview question"
.split("\\s")
.reverse()
.join(' ')