SHARE
TWEET

Untitled

advictoriam Jan 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top