View Problem

Reverse the words in a string

Given the string "This is a end, my only friend!", produce the string "friend! only my end, the is This"
DiskEdit
python
' '.join(reversed("This is a end, my only friend!".split()))
DiskEdit
clojure
(require '[clojure.contrib.str-utils2 :as str])
(str/join " " (reverse (str/split "this is the end, my only friend!" #" ")))
DiskEdit
clojure
(apply str (interpose " " (reverse (re-seq #"[^\s]+" "This is the end, my only friend!"))))
ExpandDiskEdit
erlang
Reversed = string:join(lists:reverse(string:tokens("This is the end, my only friend!", " ")), " "),
ExpandDiskEdit
java
List list = new ArrayList();
StringTokenizer st = new StringTokenizer(text, " ");
while(st.hasMoreTokens()) {
list.add(0, st.nextToken());
}
StringBuffer sb = new StringBuffer();
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
String word = (String) iterator.next();
sb.append(word);
if (iterator.hasNext()) {
sb.append(" ");
}
}
String reversed = sb.toString();
ExpandDiskEdit
java 1.5 or later
List<String> ls = Arrays.asList("This is the end, my only friend!".split("\\s"));
Collections.reverse(ls);
StringBuilder sb = new StringBuilder(32); for (String s : ls) sb.append(" ").append(s);
String reversed = sb.toString().trim();
ExpandDiskEdit
java org.apache.commons
String reversed = StringUtils.reverseDelimited("This is the end, my only friend!", ' ');

Submit a new solution for python, clojure, erlang, or java
There are 20 other solutions in additional languages (cpp, csharp, fantom, fsharp ...)