public static String reverseWords( String src ) { List<String> pcs = Arrays.asList( src.split("\\s+") ); Collections.reverse( pcs ); StringBuffer result = new StringBuffer(); for( String pc : pcs ) result.append(" ").append(pc); return result.substring(1); }
In reply to Re: Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell) (a Java 1.5 version)
by IulianU
in thread Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)
by eyepopslikeamosquito
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |