Question: String To List of Words a method called stringToListOfWords() which takes in a String converts it into a list of words. We assumes that each

String To List of Words

a method called stringToListOfWords() which takes in a String converts it into a list of words. We assumes that each word in the input string is separated by whitespace.

If our input String is "Hello, world!", then the output should be ["Hello,", "world!"]. For extra credit, sanitize the String, cleaning it up so that we remove the punctuation and other extraneous characters such that the output in the above example would become ["Hello", "world"] This method returns List.

Remove All Instances

a method called removeAllInstances() which takes in a List and item4 . The method then proceeds to remove each item in the list that matches the given item. For example, if the method is passed the List [1, 4, 5, 6, 5, 5, 2] and the Integer 5, the method removes all 5's from the List. The List then becomes [1, 4, 6, 2]. It should return nothing, since the changes the List it was provided.

Use static genetic methods if it need to be there.

String To List of Words a method called stringToListOfWords() which takes in

1 Static Generic Methods Most of the methods we write in class won't be static, but that's no reason not to learn how to do that. Java makes writing generic methods look intimidating, but in reality, it's not so bad. I'll walk you through how to do it by showing what we want to do, hitting an error, and then showing you how to resolve the error. Suppose we want to write a method called in, which given a List and an item, checks to see if the List contains that item. 1 We don't know what type the item will, nor do we know what kind of stuff the List will be holding, as that will change from one program to another, and we want this method to be able to be used in any kind of context. That means we want it to be generic. However, if we write //this is an error public static boolean in(List list, E item){ } We get \"E cannot be resolved to a type\" as an error. This happens because Java doesn't know that you want to use E as the symbol for generics for this method. We can x this by adding a in between static and our return type, like so: public static (E) boolean in(List list, E item){ } The big difference here between a class that uses a generic, like ArrayList, and the static methods you write here is that the generic type only exists for the method

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!