how can I concatenate two arrayLists
in
Programming Questions
•
2 years ago
hello everyone, I'm trying to create an agent based script which will contain 2 groups of agents with different behavior...for that I've created 2 array lists for each group, and a class for each one (in this way I'm able to control separately the behavior for each)...as a next step I wana make this 2 groups to interact when they meet...any ideeas how to make that possible?...who to concatenate these 2 array lists? or there is a more efficient way ?
here is my script
//initialize
ballCollection = new ArrayList();
ballCollection_1 = new ArrayList();
ballCollection_2 = new ArrayList();
ballCollection = concat(ballCollection,ballCollection_1);
for ( int i = 0; i < agentsN; i++) {
Vec3D origin = new Vec3D(random(vx), random(vy), start);
Ball myBall = new Ball(origin);
ballCollection.add(myBall);
}
for ( int i = 0; i < agentsN; i++) {
Vec3D origin_1 = new Vec3D(random(vx), random(vy), start_1);
Ball_1 myBall_1 = new Ball_1(origin_1);
ballCollection_1.add(myBall_1);
}
here is my script
//initialize
ballCollection = new ArrayList();
ballCollection_1 = new ArrayList();
ballCollection_2 = new ArrayList();
ballCollection = concat(ballCollection,ballCollection_1);
for ( int i = 0; i < agentsN; i++) {
Vec3D origin = new Vec3D(random(vx), random(vy), start);
Ball myBall = new Ball(origin);
ballCollection.add(myBall);
}
for ( int i = 0; i < agentsN; i++) {
Vec3D origin_1 = new Vec3D(random(vx), random(vy), start_1);
Ball_1 myBall_1 = new Ball_1(origin_1);
ballCollection_1.add(myBall_1);
}
1