我有以下代码:
DataPoint dbPoint[] = new DataPoint[] {
new DataPoint(0, 1),
new DataPoint(1, 5),
new DataPoint(2, 3),
new DataPoint(3, 2),
new DataPoint(4, 6)
};
我希望在内部删除新的DataPoint(x, y)
值,因此我可以执行以下操作:
DataPoint dbPoint[] = new DataPoint[] {};
dbPoint[].add(new Data(1,1);
dbPoint[].add(new Data(2,5);
dbPoint[].add(new Data(3,7);
dbPoint[].add(new Data(4,3);
dbPoint[].add(new Data(5,9);
谢谢!
答案 0 :(得分:1)
构建List
并使用toArray()
转换为数组
请记住,数组不能调整大小,但像List
这样的集合可以。
ArrayList<DataPoint> points = new ArrayList<>();
points.add(new DataPoint(0, 1));
points.add(new DataPoint(1, 5));
points.add(new DataPoint(2, 3));
points.add(new DataPoint(3, 2));
points.add(new DataPoint(4, 6));
DataPoint[] dbPoint = points.toArray(new DataPoint[points.size()]);
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dbPoint);