Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ExampleArrayList {
- //Create an array list ..... notice under class name not under any methods = field = can be seen by anywhere in this class because we want to use it anywhere]
- // this list is still empty (has not been initialized)
- public static List aList;
- //create a method call do stuff
- public static void main(String[] args) {
- //Initialize (create) an arraylist of type Integer (to keep numbers),, notice that we can call aList here because aList is a field
- aList = new ArrayList<Integer>();
- //this is called a local variable, cannot be called by anywhere else except in this method
- List bList = new ArrayList<Integer>();
- //add 0 - 10 to the list
- for (int i = 0; i < 10; i++) {
- aList.add(i);
- }
- for (int i = 0; i < 10; i++) {
- System.out.println(aList.get(i));
- }
- }
- public void doIllegalStuff() {
- //bList.add(5); This is not possible because bList is a local variable
- }
- public void hintForPloy() {
- /*
- So i showed you about an arrayList of Integer
- but you need arrayList of Location == > ArrayList<Location>
- and an arraylist of timer ==> ArrayList<Timer>
- /*
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement