Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help with ArrayList<Integer>

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help with ArrayList<Integer>

    Deleted for privacy.
    Last edited by shanklove; September 7th, 2010 at 04:57 PM.

  2. #2
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with ArrayList<Integer>

    Have you read about java.util.Set?, take a look then refactor your code.
    Eduardo Yáñez Parareda
    http://serfj.sourceforge.net - Simple Ever REST Framework for Java
    http://serfj.wordpress.com

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Help with ArrayList<Integer>

    Ok, so what is wrong with this process:

    1. Combine the two ArrayLists using ArrayList.addAll(Collection<? extends E> c)
    2. Go through the new ArrayList and remove all duplicates. This can be done in two ways:
    A) (Standard Way) Embedded For loops where the first For loop goes through the entire ArrayList to get an Object, and the second For loop goes through the ArrayList again seeing if that Object is found in another place in the ArrayList.
    B) (Fun Way) For Loop that goes through entire ArrayList. For each instance, use the AbstractList.lastIndexOf(Object o) method. If the returned index is not equal to current index, remove the object in the returned index and check for the current object in the ArrayList again. Once the returned index is equal to the current index, you know that Object is not repeated in the ArrayList anymore.

  4. The Following 2 Users Say Thank You to aussiemcgr For This Useful Post:

    Json (September 6th, 2010), shanklove (September 7th, 2010)

Similar Threads

  1. How to use an ArrayList and what is its advantage over array?
    By JavaPF in forum Java SE API Tutorials
    Replies: 4
    Last Post: December 21st, 2011, 04:44 AM
  2. Ordering ArrayList by 3 conditions as you add to ArrayList
    By aussiemcgr in forum Collections and Generics
    Replies: 4
    Last Post: July 13th, 2010, 02:08 PM
  3. int and Integer
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: December 31st, 2009, 03:20 AM
  4. Arraylist or Arraylist Object?
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: September 11th, 2009, 02:08 AM
  5. [SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int??
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: August 16th, 2009, 01:11 PM