拆分字符串数组的元素不能用作函数输入?

时间:2016-02-27 01:49:00

标签: java arrays input split

这是我的代码:

// This is the bug - this works.
String[] lst = {"desk", "pencil"};
String lst0 = lst[0];
System.out.println("path: " + lst[0]);
System.out.println("result: " + root.getDirectory(lst0).getFileName());

// This is the bug - this doesn't work.
String[] ef = "desk/pencil".split("/");
String ef1 = ef[0];
System.out.println("path: " + ef1);
System.out.println("result (without getFileName): " + root.getDirectory(ef1));

但是在第二种情况下,函数没有被正确调用,因为编译器认为ef [0]与lst [0]不同,尽管两者都是字符串。我假设这是因为列表拆分导致的数组。有没有办法解决/解决这个问题?

0 个答案:

没有答案