Skip to content

Commit

Permalink
Added 2D ArrayList
Browse files Browse the repository at this point in the history
  • Loading branch information
NMKrastev committed Jun 30, 2022
1 parent 4f76b25 commit d9ab03c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 06-ArrayList/06-ArrayList.iml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/out/production/" />
<output url="file://$MODULE_DIR$/out/production" />
<output-test url="file://$MODULE_DIR$/../out/test/06-ArrayList" />
<exclude-output />
<content url="file://$MODULE_DIR$">
Expand Down
13 changes: 13 additions & 0 deletions 07-2DArrayList/07-2DArrayList.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/out/production/" />
<output-test url="file://$MODULE_DIR$/../out/test/07-2DArrayList" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file added 07-2DArrayList/out/production/Main.class
Binary file not shown.
36 changes: 36 additions & 0 deletions 07-2DArrayList/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.*;
public class Main {
public static void main(String[] args) {

//2D ArrayList - a dynamic list of lists
//You can change the size of these lists during runtime
ArrayList<String> bakeryList = new ArrayList();
bakeryList.add("flour");
bakeryList.add("butter");
bakeryList.add("eggs");

ArrayList<String> produceList = new ArrayList();
produceList.add("tomatoes");
produceList.add("cucumbers");
produceList.add("zucchini");

ArrayList<String> drinkList = new ArrayList();
drinkList.add("coca-cola");
drinkList.add("coffee");

//Adds all the Lists to one Lists
//Note: It's more organized
ArrayList<ArrayList<String>> groceryList = new ArrayList();
groceryList.add(bakeryList);
groceryList.add(produceList);
groceryList.add(drinkList);

//System.out.println(bakeryList.get(0));
//System.out.println(drinkList);
System.out.println(groceryList);
//Get one List from the 2D ArrayList
System.out.println(groceryList.get(0));
//Get certain element/value from one List inside 2D ArrayList
System.out.println(groceryList.get(2).get(0));
}
}

0 comments on commit d9ab03c

Please sign in to comment.