Consider a string which is needed to be inserted in some query or file where the length of string should be equal to 40. If length of string is less than 40, then it should append empty characters till length 40 is achieved, and then it needs to be inserted. How should I do this?
void addstring(String str)
{
int len=str.length();
PrintStream out=new PrintStream();
if(len<=40)
{
out.print(str);
}
else
{
//make the string of length 40 by appending blank character and write to the file.
}
}