LinkedList
int i = 0, m = 6;
while(i!=m){
int temp = sc.nextInt();
int temp2 = sc.nextInt();
// Make sure the list is initialized before adding to it
if (vertex[temp] == null) {
vertex[temp] = new LinkedList
}
vertex[temp].add(temp2);
i++;
}
//initialize array
LinkedList
//initialize array elements(objects of LinkedList)
for (int j=0; j<5; j++)
vertex[i]=new LinkedList
int i = 0, m = 6;
while(i!=m){
int temp = sc.nextInt();
int temp2 = sc.nextInt();
vertex[temp].add(temp2);
i++;
}
Normally Arrays are not encouraged in Java. Alternatively you can use this:
//initialize array
List
//initialize arraylist elements(objects of LinkedList)
for (int j=0; j<5; j++)
vertex.add(new LinkedList