Pages

Get substring from String

Complete source code below will show you, how to get substring from a String.

**********************************************************************
COMPLETE SOURCE CODE FOR : GetSubstringFromString.java
**********************************************************************


public class GetSubstringFromString
{
public static void main(String[]args)
{
//This source code will show you how to get substring from a String
//We will get String "love" from String "I love you"
String a="I love you";

//We will use substring() method
//2=index in "I love you" for 'l'
//6=(index in "I love you" for 'e')+1
String b=a.substring(2,6);

//Print substring that we get
System.out.println(b);
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************
Related Posts Plugin for WordPress, Blogger...