Interview Question

Senior Member of Technical Staff Interview Palo Alto, CA

How do you reverse print a string. After answering the same

  by providing an out of the box API, the next unexpected question was "What if it does NOT exist". While and 2nd alternative was provided, it was pretty much shot down as being not acceptable.
Answer

Interview Answer

3 Answers

0

Use String tokenizer, dump to array and print the array in reverse. However, the prompt response to that answer was "What if there is NO stringtokenizer?" Stringtokenizer is an Out Of The Box API in java.util.

Interview Candidate on Aug 1, 2012
0

maybe try something like this
StringBuilder sb = new StringBuilder(str);
sb.reverse();

Anonymous on Oct 31, 2012
0

string.split('').reverse().join('');

Munib on Dec 2, 2013

Add Answers or Comments

To comment on this Question, Sign In with Facebook or Sign Up