Dynamic Arrays?

+1 Austin Elliott · February 28, 2015
In my Java class we are currently learning about Dynamic Arrays, but the problem is that the lesson does not teach you how to use them, or the syntax, or anything like that. It tells you what you MIGHT use it for, then it throws you into an example program that is (in my opinion) way too complex for where the class is at right now.

So, what exactly is a Dynamic Array and how do I use it?

Everytime I Google it, it returns something about ArrayList, which is not was I need.

Post a Reply


- page 2
Oldest  Newest  Rating
+1 Branislav Lazic · February 28, 2015
ArrayList is actually what you need! ArrayList is one of implementation of generic List interface.
List is a collection that takes multiple objects (instances) of same type (it can contain duplicates). It cannot contain objects of different type. I.e. 

List list = new ArrayList();

To add new object call "add" method:

list.add(new Student());

To iterate over list you may use "for each" loop:

for(Student s : list) {
    // do stuff with "s"

or "forEach" method (only Java 8):

list.forEach(s -> { // do stuff with "s" });

You may convert it to "stream" to filter results i.e.:

List filteredList = list.stream().filter(s -> s.getAge() > 18).collect(Collections.toList());

Returns list where students age is greater then 18.

  • 1
  • 2

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator