【带有ArrayList的Java OutOfMemoryError>】教程文章相关的互联网学习教程文章

java – 如何通过接口传递Object ArrayList?【代码】

我将界面定义为public interface QueryCompleteListener {void onQueryCompleted(int token, ArrayList<Object1> songList); }我正在使用此接口返回回调.在一些回调中,我想传递ArrayList< Object1>在某些情况下,我想传递ArrayList< Object2>通过界面. 如果我声明接口方法为void onQueryCompleted(int token, ArrayList<Object> songList)为了传递任何类型的Object,当我通过传递ArrayList< Object1>来调用此方法时,它会发出错误说找...

java – 寻找将ArrayList转换为double []数组的更好方法【代码】

我一直在寻找将ArrayList转换为double []数组的解决方案.在阅读了同一问题的几个问题后,我找到了解决方案.这就是我现在的工作方式.public static double[] listToArray(List<Double> arr){ double[] result = new double[arr.size()];Iterator<Double> itr = arr.iterator();int i = 0 ; while(itr.hasNext()){try{result[i] = Double.parseDouble(itr.next().toString());i++;}catch(IndexOutOfBoundsException e){System.out.p...

Java集合源码分析(一)——ArrayList源码分析【图】

一、如何看源码: 看数据结构:底层数据结构 看继承结构:类的层次结构,处于一个什么样的位置 看构造方法:看看做了哪些事,跟踪方法里面的方法 看常用的方法:与构造方法类型,看看该方法是如何实现的 二、ArrayList源码分析: 1、数据结构: ArrayList是基于数组,数组元素类型为Object,即可以存放所有类型的数据 2、继承结构:问题1:为什么要用AbstractList实现List,然后ArrayList继承AbstractList呢 答:由于接口中包含的都...

java – 如何初始化arraylist的arraylist【代码】

以下行将使用值为true的9个元素初始化arraylist.public ArrayList<Boolean> timeTable = new ArrayList<Boolean>(Collections.nCopies(9, true));但是我如何初始化arraylist的arraylist呢?public ArrayList<ArrayList<Boolean>> timeTable = new ArrayList<ArrayList<Boolean>>(Collections.nCopies(9, true));它应该意味着外部的arraylist有9个内部arraylist和每个内部arraylist有9个元素具有真正的价值. 与How can I initialize...

java – Arraylist到Array转换 – toArray()函数推断类型不符合上限错误【代码】

这是代码sinplet:Excel excel = new Excel(); ArrayList<Integer> a1=excel.readExcelSheet("C:\\Users\\Madhukar\\Desktop\\Employee.xls");System.out.println("Using Iterator");Iterator iterator = a1.iterator();while (iterator.hasNext()) {System.out.println(iterator.next());}int x=a1.size();int[] a3=new int[x];a3=a1.toArray(a3);这是错误消息:no suitable method found for toArray(int[])method AbstractColle...

Java无法识别ArrayList中的元素?【代码】

我有一个程序,我在那里制作一个arraylist来保存一些cab对象.我一直得到一个错误,我从消息中得到的是java不能识别arraylist中有对象.这是我得到的错误.Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 20, Size: 20at java.util.ArrayList.rangeCheck(Unknown Source)at java.util.ArrayList.get(Unknown Source)at edu.Tridenttech.MartiC.app.CabOrginazer.main(CabOrginazer.java:48)这是我试图开始工...

java – 为什么在一个ArrayList中改变一个对象会在所有其他ArrayLists中改变它?【代码】

我正在制作一个cpu调度模拟器(用于学校项目).我的roundRobin函数有问题.当我做c.get(i).jobTime – = 2;和c.get(i).jobTime – = 1;它影响我的其他ArrayLists,所以我不能做我的其他功能.在我调用roundRobin2之前,我的列表完全正常.为什么会这样? 例如,这是我的list4在roundRobin2之后的样子 清单4:[Job101 0,Job102 0,Job103 0,Job104 0,Job105 0,Job106 0] 这是我在文件中读取的方式,并将Jobs对象放入我的ArrayLists中.Scan...

java – 在ArrayList中插入不同的数组【代码】

我在ArrayList中插入了一个数组,但在插入第二个数组后,第一个数组与第二个数组相同. 主类:public static void main(String[] args) {ArrayList<int[]> list = new ArrayList<>();int[] parent = new int[4];for (int i = 0; i < 2; i++) {parent[0] = rand(4,1);parent[1] = rand(6, -2);parent[2] = rand(2, 1);parent[3] = rand(-1, -2);list.add(parent);}// to print the arrays of the parentfor (int i = 0; i < 2; i++) {i...

java:期望使用ArrayList【代码】

我有一个名为Storage的类.存储包含一个名为Products的特殊对象的arraylist.每个产品都包含名称,价格等信息.我的代码如下:class Storage{Product sprite = new Product("sprite",1.25,30);Product pepsi = new Product("pepsi",1.85,45);Product orange = new Product("orange",2.25,36);Product hershey = new Product("hershey",1.50,33);Product brownie = new Product("brownie",2.30,41);Product apple = new Product("apple"...

java – 将对象从文件加载到arrayList【代码】

我不知道如果我不知道有多少对象,我应该如何从列表中读取对象?保存更容易,因为我使用ArrayList中存储所有对象的对象数量.像这样的代码:// Save all customer object from customerList for(int j=0; j < customerList.size(); j++) {outObjectStream.writeObject(customerList.get(j)); }我的想法是使用类似的东西加载文件中的所有对象,并在清除后将它们一个接一个地添加到ArrayList.但正如我所写,当我不知道文件中的对象数量时,...

java – 将两个arrayList引用到相同的对象【代码】

我有这个代码.但我不知道如何解释结果:ArrayList<String> first = new ArrayList<String>();first.add("1");first.add("2");first.add("3");ArrayList<String> second = new ArrayList<String>();second = first;System.out.println("before modified:"+second.size());second.clear();System.out.println("after modified:");System.out.println(" First:"+first.size());System.out.println(" Second:"+second.size());结果...

java – 为什么ArrayList在从多个线程修改时不会抛出ConcurrentModificationException?【代码】

ConcurrentModificationException:当不允许此类修改时,检测到并发修改对象的方法可能抛出此异常. 以上是来自javadoc的ConcurrentModificationException定义. 所以我尝试测试下面的代码:final List<String> tickets = new ArrayList<String>(100000); for (int i = 0; i < 100000; i++) {tickets.add("ticket NO," + i); } for (int i = 0; i < 10; i++) {Thread salethread = new Thread() {public void run() {while (tickets.s...

java – 尝试读取parcel ArrayList时出现NullPointerException【代码】

我有一个实现Parcelable的类Message.它部分包含一个ArrayList,AttachmentsData也是我的一个类.当我尝试将MessageObject从我的MainActivity传递到另一个活动时,我在尝试读取此ArrayList时得到NullPointerException.AttachmentsData还实现了Parcelable. 错误:FATAL EXCEPTION: main java.lang.RuntimeException: Unable to startactivityComponentInfo{com.example.incentive/com.example.incentive.Comments}:java.lang.NullPointe...

java – arraylist初始化错误【代码】

我在初始化ArrayLists时遇到问题. 当我使用NetBeans 7.3时,我尝试这样做:protected Stack<Scope> scopeStack; protected ArrayList<Scope> allScopes; scopeStack = new Stack<>(); allScopes = new ArrayList<>();该文件完美编译,并且运行良好. 但是当我使用命令行切换到linux来编译java时.它给了我一个错误src/SymbolTable.java:28: illegal start of type scopeStack = new Stack<>(); SymbololTable.java:29: illegal s...

java – 如何从arraylist中的strings.xml调用字符串【代码】

我使用的是ArrayList,并且所有字符串都在适配器中进行了硬编码,但现在我需要为我的应用程序提供多语言支持.我认为最好的方法是将我所有的硬编码字符串移动到strings.xml文件中,然后生成我需要的所有不同语言的字符串文件. 我已经将硬编码字符串移动到我的strings.xml但我现在不确定如何在Arraylist中调用它们而不是在那里使用硬编码字符串.public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {List<AdapterDa...