Showing posts with label string interview. Show all posts
Showing posts with label string interview. Show all posts

Saturday, March 23, 2013

Reverse a String in Java

How to reverse a String in java?

Input: javaonjava
Output: avajnoavaj

Well there are some complex approaches to it. Storing the String as character array and then reverse the character array. Convert it back to String.

But since Java is Java. We have all the support available.




Monday, January 9, 2012

Remove multiple spaces in a String

How to remove multiple spaces inside a String and just leave single space.

Eg: Input: "java          on    java"
      Output: "java on java"


Answer:
In Java, there is function replaceAll, we can simply use that as below, In C this was a bit cumbersome to do, but as they say, Java is Java. We can do it easy here.