How can you reverse a string?

Answer Posted / milind s

Most of time in interview asked without using Build Function**

public String reverse(String arg)
{
String tmp = null;
if (arg.length() == 1)
{
return arg;
}
else
{
String lastChar = arg.substring(arg.length() - 1,
arg.length());
String remainingString = arg.substring(0,
arg.length() - 1);
tmp = lastChar + reverse(remainingString);
return tmp;
}
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When parseint method can be used?

543


What is function and its uses?

574


What is method in java with example?

493


Why collection doesn’t extend cloneable and serializable interfaces?

649


why Java does not support multiple inheritances?

706






Why we cannot override static method?

563


Is array a class in java?

508


What an i/o filter in java programming?

608


What is ‘has a’’ relationship in java?

726


Why destructor is not used in java?

526


What is meant by attribute?

595


What is the difference between final, finally and finalize()?

548


What is the advantage of functional interface in java 8?

527


What is a pattern what is an anti pattern?

512


Does string isempty check for null?

569