Source Code : String split

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

String split

String split
   
public class StyleSplitExample {
  public static void main(String args[]) {
    String phrase1 = "but simple justice, not charity";
    strengthenSentence(phrase1);

    String phrase2 = "but that I love Rome more, not that I love Caesar less";
    strengthenSentence(phrase2);

    String phrase3 = "ask what you can do for your country, ask not what your "
        + "country can do for you";
    strengthenSentence(phrase3);
  }

  public static String strengthenSentence(String sentence) {
    String retval = null;

    String[] tokens = null;

    String splitPattern = ",";

    tokens = sentence.split(splitPattern);

    if (tokens == null) {
      String msg = "   NO MATCH: pattern:" + sentence
          + "
             regex: " + splitPattern;
    } else {
      retval = tokens[1] + ", " + tokens[0];
      System.out.println("BEFORE: " + sentence);
      System.out.println("AFTER : " + retval + "
");
    }
    return retval;
  }
}

           
         
    
    
  

Thank with us