I have a java program called "run.java" which calls another program 开发者_C百科called "Main.java".
Main.java takes as an argument a LinkedList. So i should pass this LinkedList from run.java to Main.java
so, in Main.java, how can I cast the argument from string to LinkedList ?
If you want to transform an array of strings (String[] args
) into a linked list, then use this code :
LinkedList<String> argsAsLinkedList = new LinkedList<String>(Arrays.asList(args));
But a method should almost never take a LinkedList as argument. It should take a List. Use interfaces rather than concrete classes for your arguments : it allows your method to work with other kinds of lists.
You will have to tokenize your String, have a look at the StringTokenizer class.
精彩评论