Substring()

 
package substring; 
public class Substring { public static void main(String[] args) { 
String s1="James Frazer"; 
String sub1=s1.substring(0,s1.indexOf(" ")); 
String sub2=s1.substring(s1.indexOf(" ")+1); 
System.out.println("-"+sub1+"-"); System.out.println("-"+sub2+"-"); } 
} 

Outputs:

-James-
-Frazer-

Leave a Reply