java - How can I move the first word to the end? -


enter line of text. no punctuation please.
java language
have rephrased line read:
is language java

this example, , know char method, don't know how move first word end. string method can use?

what do:

  1. split sentence using string.split();
  2. create list items
  3. reorder list
  4. join list items using space

implementation in plain java:

final string s = "java language"; final list<string> list =     new arraylist<string>(arrays.aslist(s.split("\\s+"))); list.add(list.size() - 1, list.remove(0)); final stringbuilder sb = new stringbuilder(); for(final string word : list){     if(sb.length() > 0){         sb.append(' ');     }     sb.append(word); } system.out.println(sb.tostring()); 

implementation using guava:

final string s = "java language"; final list<string> list =     lists.newarraylist(splitter         .on(charmatcher.whitespace)         .omitemptystrings()         .split(s)); list.add(list.size() - 1, list.remove(0)); system.out.println(joiner.on(' ').join(list)); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -