Advertisement
JeffGrigg

Untitled

Mar 10th, 2018
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.73 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Random;
  3.  
  4. public class MillionNull {
  5.     private static final int ONE_MILLION = 1_000_000;
  6.    
  7.     public static void main(String[] args) {
  8.         final ArrayList<Object> myArrayListVariable = getObjects();
  9.  
  10.         System.out.println(myArrayListVariable.indexOf(null));
  11.     }
  12.  
  13.     private static ArrayList<Object> getObjects() {
  14.         final ArrayList<Object> myArrayListVariable = new ArrayList<>(ONE_MILLION);
  15.         final Random random = new Random();
  16.         for (int idx = 0; idx < ONE_MILLION; ++idx) {
  17.             myArrayListVariable.add(random.nextInt());
  18.         }
  19.         myArrayListVariable.set(ONE_MILLION / 2, null);
  20.         return myArrayListVariable;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement