How can you reverse a string?

Answers were Sorted based on User's Feedback



How can you reverse a string?..

Answer / palemraju

String str="how r u";
int length=str.length();
System.out.print("The reverse String is:");
while(len>0)
{
System.out.print(str.charAt(len-1));
len--;
}

Is This Answer Correct ?    11 Yes 2 No

How can you reverse a string?..

Answer / patil abhijeet

Use String buffer
StringBuffer stb = new StringBuffer(string)
stb.reverse()

Is This Answer Correct ?    7 Yes 1 No

How can you reverse a string?..

Answer / 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

How can you reverse a string?..

Answer / haneef

public class Main {
public static void main(String[] args)
{
String str1="HANEEF";
for(int i=str1.length();i>0;i--)
{
System.out.print(str1.charAt(i-1));
}
}
}

Is This Answer Correct ?    1 Yes 0 No

How can you reverse a string?..

Answer / rajesh dangi

There is no reverse method in the String class for sure.
I haven't seen such method in any other class either. The
code snippet in response 1 is the best response for this
question.

Is This Answer Correct ?    2 Yes 2 No

How can you reverse a string?..

Answer / venki from hyd

class ReverseString
{
static String name="Hello";
public static void main(String args[])
{
String rname;
for(int i=name.length(); i<0; i--)
{
rname=name.charAt(i);

}
System.out.println(rname);

}

}

Is This Answer Correct ?    1 Yes 1 No

How can you reverse a string?..

Answer / gokulprasath

StringBuilder sb= new StringBuilder("kannada").reverse();

Is This Answer Correct ?    0 Yes 0 No

How can you reverse a string?..

Answer / ravikiran(aptech mumbai)

by calling reverse() method from String class

Is This Answer Correct ?    2 Yes 9 No

Post New Answer

More Core Java Interview Questions

What are locale settings?

0 Answers  


Explain creating threads by extending thread class ?

0 Answers  


What is bitwise complement?

0 Answers  


What is jdbc api?

0 Answers  


how to make a un-checked exception as a checked exception one.

2 Answers  


Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example

0 Answers  


What is a buffer in java?

0 Answers  


Why does java not support operator overloading?

0 Answers  


How are variables stored in memory?

0 Answers  


What is meant by Static query and Dynamic query?

2 Answers  


java Technical questions asked by JPMC

0 Answers   JPMorgan Chase,


What is the difference between the synchronized() & static synchronized()?

2 Answers   HP, SparkTG,


Categories