Advertisement
paeybu

Untitled

Mar 1st, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. public class ExampleArrayList {
  2.  
  3.     //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]
  4.     // this list is still empty (has not been initialized)
  5.     public static List aList;
  6.  
  7.     //create a method call do stuff
  8.     public static void main(String[] args) {
  9.         //Initialize (create) an arraylist of type Integer (to keep numbers),, notice that we can call aList here because aList is a field
  10.         aList = new ArrayList<Integer>();
  11.  
  12.         //this is called a local variable, cannot be called by anywhere else except in this method
  13.         List bList = new ArrayList<Integer>();
  14.  
  15.         //add 0 - 10 to the list
  16.         for (int i = 0; i < 10; i++) {
  17.             aList.add(i);
  18.         }
  19.  
  20.         for (int i = 0; i < 10; i++) {
  21.             System.out.println(aList.get(i));
  22.         }
  23.     }
  24.  
  25.     public void doIllegalStuff() {
  26.         //bList.add(5); This is not possible because bList is a local variable
  27.     }
  28.  
  29.     public void hintForPloy() {
  30.         /*
  31.         So i showed you about an arrayList of Integer
  32.         but you need arrayList of Location == > ArrayList<Location>
  33.  
  34.         and an arraylist of timer ==> ArrayList<Timer>
  35.     /*
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement