Python中文网

一个关于 编程问题的解答网站.

有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

arraylist Java数组返回Null

所以当我用它来选择一个随机事件串时,它会返回一个空值:

public static List<String> pickNRandom(List<String> lst, int n) {
    List<String> copy = new LinkedList<String>(lst);
    Collections.shuffle(copy);
    return copy.subList(0, n);
}

static List<String> randomP;
public List<String> items(){
    List<String> teamList = new LinkedList<String>();
    teamList.add("team1");
    teamList.add("team2");
    teamList.add("team3");
    teamList.add("team4");
    teamList.add("team5");
    teamList.add("team6");
    List<String> randomPicks = pickNRandom(teamList, 3);
    randomPicks = randomP;
    return randomPicks;
}

public static void Store() {
    Random rand = new Random();
    int people = rand.nextInt(50) + 1;
    List<String> itemsIn = randomP;
    System.out.println("People in store: "+people + "\nItems in store: "+itemsIn);
}

public static void main(String[] args) {
    Store();

}

为什么它返回空值?我能做些什么来解决这个问题


共 (0) 个答案