Split string in Java

package javabasics;

public class StringUsage 
{

	public static void main(String[] args) 
	{
		
		String S = "India is my country";				  
		
		//Split string
		String splt[] = S.split("my");
		System.out.println("String Part 1 Is : --- "+splt[0]+"\n");
		System.out.println("String Part 2 Is : --- "+splt[1]+"\n");
		
	}

}

Output:

String Part 1 Is : --- India is 

String Part 2 Is : ---  country

 

Leave a Reply

Your email address will not be published. Required fields are marked *