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\"
String[] words = sentence.split(" "); String[] reversedWords = ArrayUtils.reverse(words); String reversedSentence = StringUtils.join(reversedWords, " ");
(using ArrayUtils and StringUtils from commons-lang, but these are easy methods to write - just a few loops)
StringUtils