Java String abbreviate and create acronym from sentence

Description

Java String abbreviate and create acronym from sentence


public class Main {
   public static String acronym(String phrase) {
      StringBuilder result = new StringBuilder();
      for (String token : phrase.split("\\s+")) {
         result.append(token.toUpperCase().charAt(0));
      }/*from  www  .j a  v  a  2s  . com*/
      return result.toString();
   }

   public static void main(String[] args) {
      System.out.println(acronym("this is a test") );
   }
}



PreviousNext

Related