Thursday, 2 February 2017

STRING SPLITTING FROM CSV (COMMA SEPARATED VALUES) IN JAVA

This concept is mostly used to extract data from .csv file which is comma separated file. Here we can specify the delimeter comma to be separated from the string and can display it in exact format.

Example –
public class Tokenizer {
          public static void main(String[] args) {
                   String csv = "Smith,Harry,Allen,Bob,Mike";
                   String name[] = csv.split(",");
                   for(String names : name)
                   {
                             System.out.println(names);
                   }
                   System.out.println();
                   System.out.println(name[3]);
          }
}

Output –
Smith
Harry
Allen
Bob
Mike
Bob 

No comments:

Post a Comment