Split in Java Example

Split Function:

 
You can split a string using regex(regular expression) or by comma or anything you want.

Here example given to split a string by comma.

String Split by Comma Java Program:
[java]
package in.javadomain;

import java.util.ArrayList;

public class CommaSplit {

public static void main(String[] args) {
String links = "http://www.google.com,http://www.facebook.com,http://www.youtube.com,http://www.ebay.com";
ArrayList linkList = new ArrayList();

// Splitting by comma and storing in string array
String[] linkSplit = links.split(",");
for (int i = 0; i < linkSplit.length; i++) {
linkList.add(linkSplit[i]);
}

// Printing ArrayList values
for (Object link : linkList) {
System.out.println(link);
}

}

}
[/java]

Output:
[plain]
http://www.google.com
http://www.facebook.com
http://www.youtube.com
http://www.ebay.com
[/plain]

Recommended Books:

One comment

Leave a Reply