Write a method

public static TreeSet getSet(String s)


which takes a String


Converts to lower case

Remove punctuation marks

Breaks into individual words using split()

Returns a TreeSet of the words

It should return the words in ascending order. Write a program which reads the string from the user, calls getSet() and displays the results.


Sample Runs


Enter String: When shall we three meet again in thunder, lightning, or in rain?


[again, in, lightning, meet, or, rain, shall, three, thunder, we, when]


Enter String: The best laid schemes o' mice an' men gang aft agley., And leave us nought but grief and pain, For promised joy.


[aft, agley, an, and, best, but, for, gang, grief, joy, laid, leave, men, mice, nought, o, pain, promised, schemes, the, us]


2. Fill a linked list with five million random values. Traverse the entire list (not print) using


Iterator with .next()

get(4999999)

Measure the elapsed time for each approach using System.nanoTime(). Report the results.

Q&A Education