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) {
    String input = "E,E,A,B,C,B,D,C";

    Set<String> set = new HashSet<String>();

    for (String s : input.split(","))
        set.add(s);//w  ww.  j av a  2  s .  c o  m

    for (String s : set)
        System.out.println(s);
}

From source file:com.vaadin.buildhelpers.FetchReleaseNotesTickets.java

public static void main(String[] args) throws IOException {
    String version = System.getProperty("vaadin.version");
    if (version == null || version.equals("")) {
        usage();//from   ww w.j  a v  a 2s  .  co m
    }

    URL url = new URL(queryURL.replace("@version@", version));
    URLConnection connection = url.openConnection();
    InputStream urlStream = connection.getInputStream();

    @SuppressWarnings("unchecked")
    List<String> tickets = IOUtils.readLines(urlStream);

    for (String ticket : tickets) {
        String[] fields = ticket.split("\t");
        if ("id".equals(fields[0])) {
            // This is the header
            continue;
        }
        System.out.println(ticketTemplate.replace("@ticket@", fields[0]).replace("@description@", fields[1]));
    }
    urlStream.close();
}

From source file:Main.java

public static void main(String[] args) {

    String str = "string1 & string2 / string3";
    String delimiters = " [/&] ";

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

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

    for (String token : tokensVal) {
        System.out.println("#" + token + "#");
    }/*from   w w w .j a v  a2 s  .  c  om*/
}

From source file:Main.java

public static void main(String args[]) {
    String testStr = "This is  a test.";
    System.out.println("Original string: " + testStr);
    String result[] = testStr.split("\\s+");
    System.out.print("Split at spaces: ");
    System.out.println(Arrays.toString(result));
}

From source file:org.kawakicchi.bookshelf.infrastructure.storage.fs.FSContentStorage.java

public static void main(final String[] args) {
    String plan = "";

    String[] ss = plan.split("/");
    for (String s : ss) {
        System.out.println("-" + s);
    }/* w w w .ja v  a 2 s .c o  m*/
}

From source file:Main.java

public static void main(String argv[]) throws Exception {
    String next = "keyword,123";
    String[] input = next.split(",");

    String textToFind = input[0].replace("'", "\\'"); // "CEO";
    String textToReplace = input[1].replace("'", "\\'"); // "Chief Executive Officer";
    String filepath = "root.xml";
    String fileToBeSaved = "root2.xml";

    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    Document doc = docBuilder.parse(filepath);

    XPath xpath = XPathFactory.newInstance().newXPath();
    // change ELEMENTS

    String xPathExpression = "//*[text()='" + textToFind + "']";
    NodeList nodes = (NodeList) xpath.evaluate(xPathExpression, doc, XPathConstants.NODESET);

    for (int idx = 0; idx < nodes.getLength(); idx++) {
        nodes.item(idx).setTextContent(textToReplace);
    }// w  w  w  .j av a 2  s  . c o m

    // change ATTRIBUTES
    String xPathExpressionAttr = "//*/@*[.='" + textToFind + "']";
    NodeList nodesAttr = (NodeList) xpath.evaluate(xPathExpressionAttr, doc, XPathConstants.NODESET);

    for (int i = 0; i < nodesAttr.getLength(); i++) {
        nodesAttr.item(i).setTextContent(textToReplace);
    }
    System.out.println("Everything replaced.");

    // save xml file back
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(new File(fileToBeSaved));
    transformer.transform(source, result);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String testStr = "One, Two, and Three.";
    System.out.println("Original string: " + testStr);
    String[] result = testStr.split("\\W+");
    System.out.print("Split at word boundaries: ");
    System.out.println(Arrays.toString(result));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String testStr = "one,   two, three";

    System.out.println("Original string: " + testStr);
    String[] result = testStr.split(",\\s*");
    System.out.print("Split at commas: ");
    System.out.println(Arrays.toString(result));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String line = URLEncoder.encode("name1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");

    String[] pairs = line.split("\\&");
    for (int i = 0; i < pairs.length; i++) {
        String[] fields = pairs[i].split("=");
        String name = URLDecoder.decode(fields[0], "UTF-8");
        System.out.println(name);
        String value = URLDecoder.decode(fields[1], "UTF-8");
        System.out.println(value);
    }//  www  . j  ava2 s .com
}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.wikipediafilter.filter.util.FileFilter.java

public static void main(String[] args) throws IOException {
    Set<String> articles = new HashSet<String>();
    articles.addAll(FileUtils.readLines(new File("target/wikipedia/articles.txt")));

    BufferedWriter writer = new BufferedWriter(new FileWriter(new File("target/passwords.txt.filtered")));
    for (String line : FileUtils.readLines(new File("target/passwords.txt"))) {
        if (articles.contains(line.split("\t")[0].toLowerCase())) {
            writer.write(line);//  w  ww  . j a  va  2 s  . c  o  m
            writer.newLine();
        }
        writer.close();
    }
}