我有这个小问题,因为它产生java.util.NoSuchElementException这个对象数组到一个向量,因为它产生java.util.NoSuchElementException我找不到什么似乎是问题。任何人都可以点似乎是个错误,请这里是代码,分裂整数数组
import java.util.Collections;
import java.util.Vector;
public class Splitting {
/**
* @param args
*/
protected int [] temp;
Vector<Integer> vec = new Vector<Integer>();
public void split(String input)
{
if (input == null)
{
String[] str;
str = input.split(",");
temp = new int[str.length];
System.out.println(str);
for (int i = 0; i < str.length; i++)
{
temp[i] = Integer.parseInt(str[i]);
vec.add(temp[i]);
}
}
System.out.println(vec);
Collections.sort(vec);
System.out.println(vec);
Collections.max(vec);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Splitting obj = new Splitting();
obj.split("12,65,21,23,89,67,12");
}
}
首先,异常通常有一个行号和堆栈跟踪。你应该向我们展示这些,他们帮助。另外,我想你想'if(input!= null)'。 – trutheality 2011-06-13 03:05:36
@Matt Ball:'Vector'是一个'List'。 – trutheality 2011-06-13 03:07:30
@trutheality:谢谢,我输入得太快了。在几乎所有情况下,应该使用'java.util.ArrayList'来代替'Vector'。 'Vector'是一个遗留类型(来自JDK 1.0)并且是'synchronized'。 – 2011-06-13 03:49:40