Welcome to Computer Programming

 

ArrayList

 

So arrays are like tables that keep track of a number of values. The problem is we need to know how many values. The alternative is ArrayList which you dont need to know many values.

 

To use an ArrayList you need to import it.

import java.util.ArrayList;

Then declare it:

ArrayList<String> myArr = new ArrayList<String>();

(If you want it to hold integers you would say:

ArrayList<Integer> numbers = new ArrayList<Integer>();

[note arraylists cant hold primitive data, thats way we are using an Integer class]

 

Now to add values we might say

myArr.add("Jeff Borland");

or

numbers.add(15);

Now to see if you arraylist has a value you could say

if (numbers.contains(14))
or any of these methods.