Advertisement
advictoriam

Untitled

Jan 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class ArrayOps
  4. {
  5.    /**
  6.        This method goes through the array of integers identified by
  7.        the only parameter, creating a new ArrayList from the array,
  8.        eliminating duplicates from the original array.
  9.        @param theArray, an array of integer
  10.        @return the new ArrayList
  11.  
  12.    */
  13.    public static ArrayList copyArray(int[] anArray)
  14.    {
  15.       ArrayList list = new ArrayList();
  16.       for(int a : anArray){list.add(a);}
  17.       for(int i = 0; i < list.size(); i++)
  18.       {
  19.          for(int j = i + 1; j < list.size(); j++)
  20.          {
  21.             if(list.get(i) == list.get(j)){list.remove(j); j--;}
  22.          }
  23.       }
  24.       return list;
  25.    }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement