Java Program to find the largest and smallest word in a string.
In this program, we need to find the smallest and the largest word present in the string:
Hardships often prepare ordinary people for an extraordinary destiny
Consider above example in which 'an' is the smallest word and 'extraordinary' is the largest word. One of the approach to find smallest and largest word is to split string into words then, compare length of each word with variables small and large. If length of a word is less than length of small then, store that word in small. If length of a word is greater than length of large then, store that word in large.
Smallest word: an Largest word: extraordinary