freetimestudys@gmail.com          +91-7097633380
  Login Here                        

replace(char oldchar,char newchar) replace(Stirng oldString,String newString):-

       by using above method we are replacing the particular character of the String. And particular portion of the string.

string replace program

class Test
{
public static void main(String[] args)
{
String str="hi freetimestudy";
System.out.println(str.replace('h','H'));
System.out.println(str.replace("study","s"));
}
}

intput and output

output:Hi freetimestudy,hi freetimes

endsWith() and startsWith():-

endsWith() is used to find out if the string is ending with particular character/string or not.
startsWith() used to find out the particular String starting with particular character/string or not.

string endsWith and startsWith

class Test
{
public static void main(String[] args)
{
String str="freetimestudy";
System.out.println(str.endsWith("y"));//true
System.out.println(str.endsWith("hi"));//false
System.out.println(str.startsWith("d"));//false
System.out.println(str.startsWith("f"));//true
}
}

intput and output

output:true,,false,,false,,true

substring(int startingposition) & substring(int startingposition,int endingposition):-


By using above method we are getting substring from the whole String.
In the above methods
starting position parameter value is including
ending position parameter value is excluding

substring:-

class sup
{
public static void main(String[] args)
{
String str="freetimestudy";
System.out.println(str.substring(2));
System.out.println(str.substring(1,7));
System.out.println("ratansoft".substring(2,5));
}
}

intput and output

output:eetimestudy ,,reetim ,,tan