gpt4 book ai didi

JAVA - 在主方法中创建数组列表并在其他类中使用它而不重新创建它

转载 作者:太空宇宙 更新时间:2023-11-04 11:15:20 25 4
gpt4 key购买 nike

这是我在 Main 方法中的数组:

ArrayList<String> myarray = new ArrayList<>();
while(scan.hasNextLine()){
myarray.add(scan.nextLine());
}
scan.close();

我的应用程序有多个线程,我试图在每个线程中使用这个数组(有点巨大),而无需每次都重新创建该数组。主要思想是以某种方式加载它并准备好被其他类调用。

最佳答案

也许下面的内容能给你一些想法

class Myclass{
private ArrayList<String> myarray = new ArrayList<>();
main(){
//populate the array
}
public ArrayList<String> getList(){
return myarray;
}

}

关于JAVA - 在主方法中创建数组列表并在其他类中使用它而不重新创建它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45513530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com