import java.util.*; /*For this program, I'm going to assume we have a simple * list of pairs. Nothing more. *IMPORTANT: You'll need to be more careful with your generics! */ public class Demo { public Demo() { ArrayList> list=new ArrayList<>(); populateList(list); System.out.println("Starting:"); displayList(list); //Now, let's count the total contents System.out.println("Total members: "+countify(list)); //Next, let's remove the first instance of a pair that includes '4' (also happens to be the only) obliterate(4,list); //Now, let's see the result! displayList(list); } //Generates a list of {{2,6},{4,12},{6,18}, {8,24}, {10,30}} private void populateList(ArrayList> list) { for (int i=2;i<=10;i+=2) { ArrayList pair=new ArrayList<>(); pair.add(i); pair.add(i*3); list.add(pair); } } private void displayList(ArrayList> list) { for (ArrayList pair:list) { System.out.print("{"); for (int value:pair) { System.out.print(" "+value); } System.out.println(" }"); } } private int countify(ArrayList> list) { int sum=0; for (ArrayList pair:list) sum+=pair.size(); return sum; } private void obliterate(int target, ArrayList> list) { //THIS ALGORITHM DOESN'T REALLY RESEMBLE WHAT YOU'LL BE DOING //IT ONLY DEMONSTRATES THAT REMOVING AN ENTRY FROM THE LIST IS SIMPLE //Also, you should probably use a 'for' loop here, but... didn't feel like it int idx=0; while (idx pair=list.get(idx); //Yeah, a 'loop for 2' is slightly silly for (int value:pair) if (value==target) { list.remove(idx); return; } idx++; } } /*Important details to remember: *I'm only using 'Integer' because we don't have an E here. But YOU DO. * So don't use String! *I'm only doing things like output here because we don't have a clinet. * But YOU DO. Don't do print statements anywhere within your queue! */ public static void main(String[] args) {new Demo();} }