【发布时间】:2019-01-05 22:43:01
【问题描述】:
我有一个类,其中有一个填充的 HashMap 和 ArrayList。我需要在我的其他类中访问 HashMap 和 ArrayList 中的键和值,当我这样做时,程序返回 NULL?
我的 HashMap 在这个类中:
package championsLeagueTeamGenerator;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.Collections;
public class topTier extends GroupStages {
public static ArrayList <Integer> x = new ArrayList <Integer>();
public static HashMap <Integer, String> xx = new HashMap();
public static void firstPot() {
x.add(1);
x.add(2);
x.add(3);
x.add(4);
x.add(5);
x.add(6);
x.add(7);
x.add(8);
Collections.shuffle(x);
xx.put(x.get(0), "Manchester United");
xx.put(x.get(1), "Barcelona");
xx.put(x.get(2), "Real Madrid");
xx.put(x.get(3), "Paris St Germain");
xx.put(x.get(4), "Bayern Munich");
xx.put(x.get(5), "Juventus");
xx.put(x.get(6), "Chelsea");
xx.put(x.get(7), "Liverpool");
System.out.println(xx);
}
我想在这个类中访问它:
package championsLeagueTeamGenerator;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Collection;
public class GroupStages {
public static ArrayList <String> groupA = new ArrayList<String>();
public static void groupOne() {
System.out.print(topTier.xx.get(1));
}
}
但是程序返回NULL,这是为什么呢?
【问题讨论】:
-
topTier来自哪里?
标签: java arraylist data-structures hashmap