In this Java Coding tutorial, you will learn how to reverse words in String. It's also one of the popular coding question, so you will also learn how to take requirement, how to fill gaps in requirement by asking right question. A String is nothing but a sentence, which may contain multiple works, or just contain single word or it may be empty. Your program must produce a String contains word in reverse order , for example if given input is "Java is Great" then your program should return "Great is Java". Now, if you are a good programmer then you should have some right questions for programmer. Never assume you know everything, even if its looks a simple problem. Always remember "Devil is in detail". Also asking question not only fill the gaps in requirement but also help you to make impression. One of the question candidate should definitely ask is, what constitutes a word here? For purpose of this program, word is nothing but a sequence of non-space characters. Another good question you can ask to Interview is about input, e.g. is it possible for input string to contain leading or trailing spaces? Yes, its possible. However, your reversed string should not any contain leading or trailing spaces. One more important question for Interviewer is about spacing between words, is it possible to have multiple spaces between two words? Yes, it could be possible but you can reduce them to a single space in the reversed string. BTW, if you preparing for programming job interview, you can also take a look at
Cracking the Coding Interview: 150 Programming Questions and Solutions, you will not only find some good question on array and String on this book, but also about several other key topics e.g. SQL, database, networking and Java.