Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need a java program which reverse a string with using methods.

For example,

input:-"hellojava"

output:- "avajolleh"

share|improve this question
1  
with or 'without'? –  Ahmed Masud Apr 25 at 13:17
    
Use StringBuilder it has a reverse method. –  Omoro Apr 25 at 13:45

2 Answers 2

You can directly use

String word= "hellojava";

new StringBuilder(word).reverse().toString();

for one word you need below one.

String word= "hello java";

for (String part : word.split(" ")) {
    System.out.print(new StringBuilder(part).reverse().toString());
    System.out.print(" ");
}

This is supported since java 1.5 ealier versions you should use StringBuffer. And for any Java based project you can use this method.

new StringBuffer (word).reverse().toString();
share|improve this answer

Try the next:

String output = new StringBuilder(input).reverse().toString();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.