处理 - 管理ArrayLists

问题描述:

我试图管理这个ArrayList。基本上我有一个ArrayListPVector对象 - 在我的代码中有两对(x,y)变量进入数组。我想知道如何分开管理两对。我需要知道哪一个是(x1,y1),哪一个是(x2,y2),并且可能命名它们。我怎样才能做到这一点?处理 - 管理ArrayLists

Blob(float x, float y) { 
    minx = x; 
    miny = y; 
    maxx = x; 
    maxy = y; 
    points = new ArrayList<PVector>(); 
    points.add(new PVector(x, y)); 
} 
+0

推荐阅读:[Creating Classes](http://happycoding.io/tutorials/processing/creating-classes) –

我不能完全确定要根据你的问题,以达到什么样的,但如果你想从你的blob功能创建2个PVector对象并将其添加到您的ArrayList,再加入2个该函数的参数。例如:

void blob(float x1, float y1, float x2, float y2) { 
    minx = x1; 
    miny = y1; 
    maxx = x2; 
    maxy = y2; 
    points = new ArrayList<PVector>(); 
    points.add(new PVector(minx, miny)); 
    points.add(new PVector(maxx, maxy)); 
} 

然后,您可以使用ArrayList指数识别这两个PVector对象,并给它们命名,你可以将它们分配给变量。例如:

PVector firstPoint = points.get(0); 
PVector secondPoint = points.get(1);