Skip to content

Commit 676f55e

Browse files
rahusrivKevinGilmore
authored andcommitted
BAEL-2335 (eugenp#6015)
* Making examples simple * Changing variable names
1 parent 99774f8 commit 676f55e

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

‎core-java-collections-list/src/main/java/com/baeldung/list/multidimensional/ArrayListOfArrayList.java‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,28 @@ public class ArrayListOfArrayList {
66

77
public static void main(String args[]) {
88

9-
int vertex = 5;
10-
ArrayList<ArrayList<Integer>> graph = new ArrayList<>(vertex);
9+
int numVertices = 3;
10+
ArrayList<ArrayList<Integer>> graph = new ArrayList<>(numVertices);
1111

1212
//Initializing each element of ArrayList with ArrayList
13-
for(int i=0; i< vertex; i++) {
13+
for(int i=0; i< numVertices; i++) {
1414
graph.add(new ArrayList<Integer>());
1515
}
1616

1717
//We can add any number of columns to each row
1818
graph.get(0).add(1);
19-
graph.get(0).add(5);
20-
graph.get(1).add(0);
2119
graph.get(1).add(2);
20+
graph.get(2).add(0);
21+
graph.get(1).add(0);
2222
graph.get(2).add(1);
23-
graph.get(2).add(3);
24-
graph.get(3).add(2);
25-
graph.get(3).add(4);
26-
graph.get(4).add(3);
27-
graph.get(4).add(5);
28-
23+
graph.get(0).add(2);
24+
2925
//Printing all the edges
30-
for(int i=0; i<vertex; i++) {
31-
for(int j=0; j<graph.get(i).size(); j++) {
32-
System.out.println("Edge between vertex "+i+"and "+graph.get(i).get(j));
26+
for(int vertexNo=0; vertexNo<numVertices; vertexNo++) {
27+
int edgeCount = graph.get(vertexNo).size();
28+
ArrayList<Integer> listOfVertices = graph.get(vertexNo);
29+
for(int i=0; i<edgeCount; i++) {
30+
System.out.println("Vertex "+vertexNo+" is connected to vetex "+listOfVertices.get(i));
3331
}
3432
}
3533
}

‎core-java-collections-list/src/main/java/com/baeldung/list/multidimensional/ThreeDimensionalArrayList.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ public static void main(String args[]) {
2020
}
2121

2222
//Set Red color for points (0,0,0) and (0,0,1)
23-
space.get(0).get(0).add("Red");
24-
space.get(0).get(0).add("Red");
23+
space.get(0).get(0).add(0,"Red");
24+
space.get(0).get(0).add(1,"Red");
2525
//Set Blue color for points (0,1,0) and (0,1,1)
26-
space.get(0).get(1).add("Blue");
27-
space.get(0).get(1).add("Blue");
26+
space.get(0).get(1).add(0,"Blue");
27+
space.get(0).get(1).add(1,"Blue");
2828
//Set Green color for points (1,0,0) and (1,0,1)
29-
space.get(1).get(0).add("Green");
30-
space.get(1).get(0).add("Green");
29+
space.get(1).get(0).add(0,"Green");
30+
space.get(1).get(0).add(1,"Green");
3131
//Set Yellow color for points (1,1,0) and (1,1,1)
32-
space.get(1).get(1).add("Yellow");
33-
space.get(1).get(1).add("Yellow");
32+
space.get(1).get(1).add(0,"Yellow");
33+
space.get(1).get(1).add(1,"Yellow");
3434

3535
//Printing colors for all the points
3636
for(int i=0; i<x_axis_length; i++) {

0 commit comments

Comments
 (0)