You can achieve this without using replaceAll() or any Predefined Method in Java. this way is preferred:-
public class RemoveSpacesFromString {
public static void main(String[] args) {
// TODO Auto-generated method stub
String newString;
String str = "prashant is good" ;
int i;
char[] strArray = str.toCharArray();
StringBuffer sb = new StringBuffer();
for(i = 0; i<strArray.length; i++)
{
if(strArray[i]!= ' ' && strArray[i]!= '\t')
{
sb.append(strArray[i]);
}
}
System.out.println(sb);
/*newString = str.replaceAll(" " , "");
System.out.println(newString);*/
}
}