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 args[]) throws Exception {
    String s3 = "A-BB-CCC";
    String[] words = s3.split("-");
    for (String str : words) {
        System.out.println(str);/* w  w w  . j a v a 2  s .co m*/
    }
}

From source file:Main.java

public static void main(String args[]) {
    String str = "one.two.three";
    String[] temp = str.split("\\.");
    for (String s : temp) {
        System.out.println(s);/*from ww  w  .jav a2s .c  om*/
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    String s3 = "A  BB CCC";
    String[] words = s3.split("\\s+");
    for (String str : words) {
        System.out.println(str);//w  w  w. j  a  v  a2  s.c o m
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    String s = "A.BB.CCC";

    String[] words = s.split("\\.");
    for (String str : words) {
        System.out.println(str);/*from  w  ww  . ja  v a 2s . c  o  m*/
    }
}

From source file:Main.java

  public static void main(String args[]) throws Exception {
  String s = "|A|BB||CCC|||";
  String[] words = s.split("\\|");
  for (String string : words) {
    System.out.println(string);/*from  ww w  .j a va2s .  c o  m*/
  }
}

From source file:Main.java

public static void main(String[] args) {

    String original = "java2s.com";
    String[] words = original.split("\\s+");
    System.out.print("Reversed String in Place:" + " ");
    for (int i = words.length - 1; i >= 0; i--) {
        System.out.print(words[i] + " ");
    }/*from w  w  w . j  a va2s .  co m*/
}

From source file:Main.java

public static void main(String args[]) {
    String input = "this is a test";
    String[] words = input.split(" ");
    String reverse = "";
    for (int i = 0; i < words.length; i++) {
        for (int j = words[i].length() - 1; j >= 0; j--) {
            reverse += words[i].charAt(j);
        }/*ww  w. j  a  v  a2s .c  o m*/
        System.out.print(reverse + " ");
        reverse = "";
    }
}

From source file:CountWords.java

public static void main(String[] args)
{
    System.out.print("Enter a string: ");
    String s = sc.nextLine();
    String[] word = s.split("\\s+");
    for (String w: word)
        System.out.println(w);//from w ww. j ava 2 s  .c  om
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    String s3 = "{A}{this is a test}{1234}";
    String[] words = s3.split("[{}]");
    for (String str : words) {
        System.out.println(str);//from  ww w.  j  a  v a 2s.c  o m
    }
}

From source file:Main.java

public static void main(String[] args) {
    String str = "This is a 23.4.123 test.";
    String[] s = str.split(" ");
    Pattern p = Pattern.compile("(\\d)+\\.(\\d)+");
    double d;/*  w  ww .j av a  2s .  co  m*/
    for (int i = 0; i < s.length; i++) {
        Matcher m = p.matcher(s[i]);
        while (m.find()) {
            d = Double.parseDouble(m.group());
            System.out.println(d);
        }
    }
}