Capitalize the first letter of every word in a String

Try this:

import java.util.*;
 
public class Main
{
   public static void main(String args[]) {
      String s = "this is a string";
      String s2 = capitalize(s);
      System.out.println(s2);
   }
 
   public static String capitalize(String s) {
      StringTokenizer st = new StringTokenizer(s, " ");
      StringBuffer sb = new StringBuffer();
      while (st.hasMoreElements()) {
         String el = (String) st.nextElement();
         sb.append(Character.toUpperCase(el.charAt(0)));
         sb.append(el.substring(1) + " ");
      }
 
      return sb.toString();
   }
}