How do I split a string?

Category: java.lang, viewed: 23618 time(s).

Prior to Java 1.4 we use StringTokenizer to split a tokenized string, for example a comma separated string. In Java 1.4 or later the String class introduce a String.split(String regex) method that simplify this process.

Below is a code sample how to do it.

package org.kodejava.sample.java.lang;

public class StringSplit
{
    public static void main(String[] args)
    {
        String data = "1,Diego Maradona,Footballer,Argentina";
        String[] items = data.split(",");
        for (String item : items)
        {
            System.out.println("item = " + item);
        }
    }
}
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats