tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Google Guava > Basic > Splitter

Splitter 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Splitter class. It splits the given string into substrings using the provided separator.

File Name  :  
com/bethecoder/tutorials/guava/base_tests/SplitterTrimTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.guava.base_tests;

import com.google.common.base.Splitter;

public class SplitterTrimTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    //Create a splitter that trims all tokens
    Splitter splitter = Splitter.on(",").trimResults();
    Iterable<String> iterable = splitter.split("One,    Two,Three,  Four,,  , Five");
    
    for (String tokens : iterable) {
      System.out.println(tokens);
    }
  }

}
   

It gives the following output,
One
Two
Three
Four


Five


                    Print

   



Books Recommendation

 
 
bl  br