如果list类型参数在java中具有int [],如何从列表对象中获取值。所以大家请帮忙解决这个问题。我试过自己。但我卡在了某个地方。
public class Stack {
public static int[] Varun = {94, 97, 21, 71, 80};
public static int[] Monti = {95, 90, 11, 80, 81};
public static int[] Shalini = {90, 91, 20, 71, 72};
public static int[] Kuldeep = {78, 77, 18, 90, 92};
public static int[] Arun = {71, 71, 21, 78, 98};
public static String[] performanceParameters = {"Creativity", "Communication", "TechnicalSkills", "PersonalHabits", "TakeInitiative"};
public static int[] attendenceList = {21, 11, 20, 18, 21};
public static ArrayList<int[]> parameters = new ArrayList<int[]>();
public String[] topPerformers(String[] listOfEmployees, List<int[]> parameters) {
Arrays.sort(listOfEmployees);
for(String a:listOfEmployees)
{
System.out.println(a);
}
Integer a[]=(Integer[]) parameters.toArray(new Integer[parameters.size()]);
Iterator<int[]> it=parameters.iterator();
for(int[] arr: parameters)
{
for(int item:arr)
{
System.out.println(item);
}
}
Iterator<int[]> it = parameters.iterator();
while (it.hasNext()) {
int[] arr = it.next();
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
// System.out.println(parameters.indexOf(this));
String topPerformers[] = new String[3];
Map m = new HashMap();
// m.put(listOfEmployees, parameters);
// write your code here.
return topPerformers;
}
public static void main(String[] args) {
parameters.add(Varun);
parameters.add(Monti);
parameters.add(Shalini);
parameters.add(Kuldeep);
parameters.add(Arun);
Stack s = new Stack();
s.topPerformers(performanceParameters, parameters);
}
请给我从列表对象中获取数组元素的方法。我尝试过,但我做错了什么。只是帮助完成这个。提前谢谢。
答案 0 :(得分:0)
只需在迭代器next()
中使用it
方法获取int[]
实例,然后像这样迭代它
while (it.hasNext()) {
int[] arr = it.next();
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
答案 1 :(得分:-1)
试试这个,
for(int[] arr : parameters){
for(int item:arr){
System.out.println(item);
}
}