ArrayList
保存随机数据,例如:
ArrayList<Integer> arrayList = new ArrayList<>(100);
Random r = new Random(System.currentTimeMillis());
for(int i = 0; i < 100; i++) {
arrayList.add(r.nextInt());
}
然后:
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
int yOffset = 10;
int yStartPosition = 480;
for (int i = 0; i < arrayList.size(); i++) {
Integer integer = arrayList.get(i);
canvas.drawText(String.valueOf(integer), 130, yStartPosition+(i*yOffset), black_paintbrushstroke);
}
}
StringBuilder sb = new StringBuilder();
for(int i = 0; i < arrayList.size(); i++) {
sb.append(arrayList.get(i)).append(",");
}
String myRandomNumbersArray = sb.toString();
sb.setLength(0);