I am getting error in copyOf method . Can anyone tell where am i wrong ? I am getting error :
The method `copyOf(U, int, Class<? extends T>)` in the type Arrays is not applicable for the arguments (Object, int, Class<String>)
Can only iterate over an array or an instance of `java.lang.Iterable
Welcome to the Ranch I added code tags to your post; doesn't it look better now
Why have you got a static variable (the List) and why isn't it marked private? You have got too much code in the main method. It is intended only for starting an application, not to be the whole application.
You aren't closing the Scanner; find out how to close it with try with resources.
You have to do something about the exception declared by line 5.
Why don't you use the overloaded version of List#toArray(): String words = myList.toArray(new String); Have you read the documentation for Arrays#copyOf()? You have a U, which you are using as the source, In which case U means Object. You are now trying to copy it into a String, so you need some sort of class that extends T not T. Since String is a final class, the only class you can find to extend String is String.class. That is what it means about Class<? extends T>. Whichever type of Class object you are passing has to represent something extending T.