Q:

How to spilt string in substrings using String.split() in Java?

belongs to collection: Java String Programs

0

Given string and delimiter and we have to separate the given string in substrings.

1) String [] split (String delimiter)

This function returns array of strings, separated by delimiter (which is a string, passing as a delimiter).

2) String [] split (String delimiter, int max)

Here,
String[] - array of strings (substrings separated by given delimiter).
String delimiter - string as delimiter to split string.
int max - controls the number of substrings separated through given delimiter.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

public class JavaStringSplitPrg
{
	public static void main(String []args)
	{
		try
		{
			String str1="www.includehelp.com";
			int loop;

			String [] arrStr1;

			/*split string by delimiter ., to do this
			* you have to provide \\. */
			arrStr1 = str1.split("\\.");
			// print substrings
			for(loop=0;loop < arrStr1.length; loop++)
			{
				System.out.println(arrStr1[loop]);
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}

Output

www
includehelp
com

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to demonstrate example of String.star... >>
<< How to trim a given string using String.trim() met...