开发者

casting a java argument from String to LinkedList

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜