大家好,大家好,我已经开始学习用java收集和试图写一个简单的程序,但我得到了2个错误,请看看,并帮助我。
import java.util.Iterator;
import java.util.*;
class ArrayListDemo1{
public static void main(String... s){
ArrayList<Integer> al = new ArrayList<Integer>();
// ArrayList al = new ArrayList();
int x[] = {1, -1, 2, -2,
我正在尝试对主线程中列表的每个值进行一些计算,如下所示
for (int i = 0; i < list.size(); i++) {
//Do some task
}
但是我正在获取list.size()上的ConcurrentModificationException。
它是简单的java.util.List
Caused by: java.util.ConcurrentModificationException
下面是我得到的错误消息:
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at pie.chart.explorer.alpha.ShowPieChart.<init>(ShowPieChart.java:
我已经在F#和Scala上编写了一个列表操作函数来比较性能。为了测试这个函数,我需要初始化一个从1到100000000的列表。
F#:
let l = [1..100000000];;
真实: 00:00:32.954,CPU: 00:00:34.593,GC gen0: 1030,gen1: 520,gen2: 9
这个很管用。
Scala : Scala-J-Xmx2G选项
val l = (1 to 10000000).toList // works
val l = (1 to 100000000).toList // no response long while and final
我正在尝试使用Java中的Native Query获取车辆的有序列表。
我使用两种方法,第一种方法获取车辆,第二种方法对列表进行排序。
我得到了这个错误:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.set(AbstractList.java:132)
at java.util.AbstractList$ListItr.set(AbstractList.java:426)
at java.util.Collecti
我有下面的类来检查使用foreach循环从arraylist中删除对象。
import java.util.ArrayList;
public class CheckArrayList {
/**
* @return the a
*/
public int getA() {
return a;
}
/**
* @param a
* the a to set
*/
pub
可能重复:
我正在为Java寻找一个类似于表的数据结构。到目前为止,我还没有找到一个,这真的是令人沮丧的,因为我知道,肯定有一个。请注意,这与表的图形表示无关,只是逻辑模型。
这个想法很简单,你有一张桌子,像:
+-------+-----+-----------+
| Name | Age | city |
+-------+-----+-----------+
| Steve | 21 | London |
| John | 40 | Amsterdam |
+-------+-----+-----------+
现在,我需要迭代不同的行,并根据列名检索
最初,如果数组列表中的元素是列表中的唯一元素,则会有一个删除元素的问题,但现在在删除数组列表的最后一个位置时出现了异常问题。处理这件事最好的方法是什么?
编辑:回顾过去,检查它是否是最后一个元素,并放入一个虚拟元素来保持唯一的位置就可以了。
守则:
public void deleteCustomer(){
String id = null;
boolean c = false; //true if id is found
int remember = 0; //Remembers the deleted i
我正在尝试使用“迭代器”.remove删除这个ArrayList中具有偶数索引号的字符串。
import java.util.*;
import static java.lang.System.out;
class MAIN
{
public static void main(String args[])
{
ArrayList<String> al = new ArrayList<String>();
Iterator i = al.iterator();
int len;
Sc
如果我的空间已满,我有时会得到以下异常
java.io.IOException: No space left on device
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(FileOutputStream.java:282)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1847)
我今天在生产中遇到了一个奇怪的问题。虽然我喜欢番石榴,但我遇到了一个用例,其中番石榴的Sets.intersection()表现很差。我编写了一个示例代码:
Set<Long> cache = new HashSet<>();
for (long i = 0; i < 1000000; i++) {
cache.add(i);
}
Set<Long> keys = new HashSet<>();
for (long i = 0; i < 100; i++) {
keys.add(i);
}
long start =
我试图一个一个地接受用户的基本整数列表,并将其存储到基元数组中供以后使用。这是我的代码:
Scanner scanner=new Scanner(System.in);
int n= scanner.nextInt();
ArrayList<Integer> arr=new ArrayList<>();
int[] a = new int[arr.size()];
Iterator<Integer> iterator = arr.iterator();
if (n < 15){
for
我尝试将程序生成的所有数字附加到一个数组中。
我使用了ArrayList方法。然而,我不能管理程序来读取arr元素。
import java.util.Random;
import java.util.ArrayList;
public class Numbers {
public ArrayList<Double> getNumbers( )
{
Random getNum=new Random();
ArrayList<Double> arr=new ArrayList<Double>(1000);
int size=1000;
我需要在这个类中编写next()方法的帮助。我已经尝试了几种方法,但我总是发现返回的不是下一个值,而是null。 该类的说明为:该类应该是公共的、非静态的,并且应该实现java.util.Iterator。它的index实例变量应该使用适当的值进行初始化。如果它的hasNext()方法还没有返回队列中的任何元素,那么它的next()方法应该返回true。它的next()方法应该以与底层数组相同的顺序返回队列值。 因此,我将编写我已有的代码,但会将其缩短,以便只显示与我的问题相关的重要元素。 public class MaxHeapPriorityQueue<E extends Comp
我正在尝试编写模拟拼字游戏的代码。我设计了一个类来模拟拼写袋,我试图在选择一个随机的磁贴后在main中打印tileID来测试它。但是,每当我运行代码时,我都会得到以下错误:
Exception in thread "main" java.lang.IllegalArgumentException: bound must be positive at java.util.Random.nextInt(Random.java:388) at hw3.RandomBag.randomPick(RandomBag.java:39) at hw3.RandomBa
我在Scala中有一个程序,它读取一个CSV文件,向Dataframe添加一个新列,并将结果保存为一个parquet文件。它在小文件(<5 Go)上工作得很好,但是当我尝试使用更大的文件(~80 Go)时,它总是会失败,因为它应该用这个堆栈跟踪来编写拼花文件:
16/10/20 10:03:37 WARN scheduler.TaskSetManager: Lost task 14.0 in stage 4.0 (TID 886, 10.0.0.10): java.io.EOFException: reached end of stream after reading 136445 by
我对java还不熟悉,并且遇到了这个问题。
我有两个数据数组,每个数组都包含数字细节。
static List<String> players1 = new ArrayList<String>();
static List<String> players2 = new ArrayList<String>();
// Player 1 array plays player 2 array. List is always different on generation.
我想要做的是在while循环中使用这两个字符串来遍历每个pla