Example usage for java.lang String split

List of usage examples for java.lang String split

Introduction

In this page you can find the example usage for java.lang String split.

Prototype

public String[] split(String regex) 

Source Link

Document

Splits this string around matches of the given regular expression.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String testStr = "This;:, is:;:;:;. a!:; test?";
    System.out.println("Original string: " + testStr);
    String[] result = testStr.split("[.,!?:;]+\\s*");
    System.out.print("Split on various punctuation: ");
    System.out.println(Arrays.toString(result));
}

From source file:MainClass.java

public static void main(String args[]) {
    String secondString = "1, 2, 3, 4, 5, 6, 7, 8";

    String output = "String split at commas: [";

    String[] results = secondString.split(",\\s*"); // split on commas

    for (String string : results)
        output += "\"" + string + "\", ";

    output = output.substring(0, output.length() - 2) + "]";
    System.out.println(output);//from   ww w .ja  v  a  2  s. c  om

}

From source file:com.github.xbn.examples.io.non_xbn.ReadInActiveAccountsFromFile.java

public static final void main(String[] rqdInputPathInStrArray) {
    //Read command-line
    String sSrc = null;//from  w w  w  .  ja  va 2  s  .  c o m
    try {
        sSrc = rqdInputPathInStrArray[0];
    } catch (IndexOutOfBoundsException ibx) {
        System.out.println("Missing one-and-only required parameter: The full path to Java source-code file.");
        return;
    }

    //Open input file
    File inputFile = new File(sSrc);
    Iterator<String> lineItr = null;
    try {
        lineItr = FileUtils.lineIterator(inputFile);
    } catch (IOException iox) {
        System.out.println("Cannot open \"" + sSrc + "\". " + iox);
        return;
    }

    while (lineItr.hasNext()) {
        String line = lineItr.next();
        String[] userPassIsActive = line.split(" ");
        String username = userPassIsActive[0];
        String password = userPassIsActive[1];
        boolean isActive = Boolean.parseBoolean(userPassIsActive[2]);

        System.out.println("username=" + username + ", password=" + password + ", isActive=" + isActive + "");
    }
}

From source file:Main.java

public static void main(String[] args) {

    String str = "test from java2s.com";
    String delimiters = "\\s+|,\\s*|\\.\\s*";

    String[] tokensVal = str.split(delimiters);

    System.out.println("Count of tokens = " + tokensVal.length);

    for (String token : tokensVal) {
        System.out.println(token);
    }//from  ww w  . ja va 2s . com

    tokensVal = str.split(delimiters, 3);

    System.out.println("\nCount of tokens = " + tokensVal.length);

    for (String token : tokensVal) {
        System.out.println(token);
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    String statement = "A B AA";
    String tokens[] = null;// ww  w. j  a va  2  s .  com
    String splitPattern = "A|B|C|E|(G H I J)|(AA BB CC)";

    tokens = statement.split(splitPattern);
    System.out.println("REGEX PATTERN:\n" + splitPattern + "\n");
    System.out.println("STATEMENT:\n" + statement + "\n");
    System.out.println("TOKENS:");
    for (int i = 0; i < tokens.length; i++) {
        System.out.println(tokens[i]);
    }
}

From source file:Main.java

public static void main(String args[]) {
    String statement = " a b c abc bca cba";
    String tokens[] = null;/*  w  w w  . ja v  a2 s.c o  m*/
    String splitPattern = "a|abc|bac|" + "b|(c)|(cba)";
    tokens = statement.split(splitPattern);

    for (int i = 0; i < tokens.length; i++) {
        System.out.println(tokens[i]);
    }
}

From source file:es.cnio.bioinfo.bicycle.BinomialAnnotator.java

public static void main(String[] args) throws IOException, MathException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    double p = Double.parseDouble(args[0]);
    String line = null;

    while ((line = in.readLine()) != null) {

        String[] tokens = line.split("\t");
        int reads = Integer.parseInt(tokens[5]);
        int cCount = Integer.parseInt(tokens[4]);
        BinomialDistribution binomial = new BinomialDistributionImpl(reads, p);
        double pval = (reads == 0) ? 1.0d : (1.0d - binomial.cumulativeProbability(cCount - 1));
        if (System.out.checkError()) {
            System.exit(1);//w w  w . j a  va  2  s  .  co m
        }
        System.out.println(line + "\t" + pval);

    }
}

From source file:edu.illinois.cs.cogcomp.wikifier.utils.freebase.cleanDL.java

public static void main(String[] args) throws IOException {
    List<String> lines = FileUtils.readLines(new File("/Users/Shyam/mention.eval.dl"));

    for (String line : lines) {
        String[] parts = line.split("\\s+");
        System.out.println(parts[0] + parts[1] + parts[2]);
        StringBuilder sb = new StringBuilder();
        for (int i = 3; i < parts.length; i++)
            sb.append(parts[i] + " ");
        if (mentionFilter(parts)) {
            System.out.println("removing " + Arrays.asList(parts));
            continue;
        }/*from  w w  w.j ava2  s .c o m*/
        if (mentions.containsKey(parts[0])) {
            mentions.get(parts[0]).add(new DocMention(parts[0], sb.toString(), Integer.parseInt(parts[1]),
                    Integer.parseInt(parts[2])));
        } else {
            mentions.put(parts[0], new ArrayList<DocMention>());
            mentions.get(parts[0]).add(new DocMention(parts[0], sb.toString(), Integer.parseInt(parts[1]),
                    Integer.parseInt(parts[2])));
        }
    }
    for (String doc : mentions.keySet()) {
        handleDoc(mentions.get(doc));
    }

    outputMentions();
}

From source file:Main.java

public static void main(String[] args) {

    String text = "a r b k c d se f g a d f s s f d s ft gh f ws w f v x s g h d h j j k f sd j e wed a d f";

    List<String> list = Arrays.asList(text.split(" "));

    Set<String> uniqueWords = new HashSet<String>(list);
    for (String word : uniqueWords) {
        System.out.println(word + ": " + Collections.frequency(list, word));
    }//from  w w  w.  j a  v  a2 s  .  co  m
}

From source file:Main.java

public static void main(String[] args) {

    String str = "test from java2s.com";
    String delimiters = "\\s+|,\\s*|\\.\\s*";

    // analyzing the string 
    String[] tokensVal = str.split(delimiters);

    // prints the number of tokens
    System.out.println("Count of tokens = " + tokensVal.length);

    for (String token : tokensVal) {
        System.out.println(token);
    }//from w w  w . ja  va2  s  . c  om
}