简体   繁体   English

将整数数组添加到ArrayList <int[]>

[英]adding array of integers to ArrayList<int[]>

I have an arraylist 我有一个数组列表

ArrayList<int[]> strokeLines = new ArrayList<int[]>();

and a function which runs everytime the mouse is clicked which adds the current mouse position and the previous mouse position to this arraylist 以及每次单击鼠标都会运行的函数,它将当前鼠标位置和先前的鼠标位置添加到此arraylist

strokeLines.add({mouseX, mouseY, pmouseX, pmouseY});

I had this code working earlier but I lost everything I wrote in the past hour, and when I rewrote this part it wouldn't work. 我早些时候可以使用此代码,但是我失去了过去一个小时内编写的所有内容,而当我重写此部分时,它将无法正常工作。 How can I add the array {mouseX, mouseY, pmouseX, pmouseY} to the end of the arraylist? 如何将数组{mouseX,mouseY,pmouseX,pmouseY}添加到a​​rraylist的末尾?

您需要创建一个新的int[]

strokeLines.add(new int[]{mouseX, mouseY, pmouseX, pmouseY});

简单地-

strokeLines.add(new int[]{mouseX, mouseY, pmouseX, pmouseY});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM