Given a string of odd length, return length three from its middle- replaceALL

java replaceAll() method with example program. This kind of question are asked in codingbat. Improve your programming skills by solving this, its for beginners. Program with explanation.

public String middleThree(String str)


String newstr;

int mid;

str=str.replaceAll(“\\s” , “”);

int len=str.length();



return str;




return newstr;


Below program explain java replace() method. Syntax, example and explanation.

Program using replace method