Results 1 to 6 of 6

Thread: Remove repeated elements in an ArrayList

  1. #1
    Join Date
    Dec 2009
    Posts
    292

    Remove repeated elements in an ArrayList

    Hello,
    How can we remove repeated elements in an ArrayList?. I have tried it many times but I can not find the correct code for it. here is an example
    Code:
    ex: (16 51 54 85 54 16 51 2 3 51) -> (16 51 54 85 2 3)
    there is a special function for that? If you know what or which is the method to be used here , then please let me know about it. Thank you.

  2. #2
    Join Date
    Nov 2009
    Posts
    333

    Re: Remove repeated elements in an ArrayList

    Hello,
    We must reconstruct a new ArrayList and add items in it by checking that there are not already ..
    Code:
    public boolean contains (Object elem)
    this will returns true if this list contains the specified element.
    Code:
    public boolean add (Object o)
    Appends the specified element to the end of this list.

  3. #3
    Join Date
    Nov 2009
    Posts
    347

    Re: Remove repeated elements in an ArrayList

    Hello,
    The above explanation is correct or you can start with an algo that your route table and determines whether an index is identical to another and there a leash. then you implements in Java. If you need more information about it then you can visit the sun's official site for java , and there you can find the more detailed information for this.

  4. #4
    Join Date
    Nov 2009
    Posts
    335

    Re: Remove repeated elements in an ArrayList

    Hello,
    Code:
    Someclass lt = new ArrayList (new HashSet (monArrayList));
    This is not necessarily the most efficient but unless you have a large number of data it works very well and above all, it's easy to read and understand. Like to know what the API sometimes helps to get rid of algos , As a bonus you can even sort the result by replacing by HashSet TreeSet. Try it and if you get an error then post the error so that we can sort your problem and make the program run successfully.

  5. #5
    Join Date
    Nov 2009
    Posts
    446

    Re: Remove repeated elements in an ArrayList

    Hello,
    Get rid of the algorithm is to deprive a good reflection of development. not bad in itself to use the api. But I can not help it I formatted like that. Algo code then that's all. So I always have a pen and a sheet. but for small program you can do without, but for an app. I think seeing the demand for the program that is been asked you can use the above method easily without any problem.

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: Remove repeated elements in an ArrayList

    Hello,
    What is the interest of wasting time reinventing something that exists in the API? This is especially true for large applications or it has to do better. The most important is when using the API was not adapted. As I said in that case it must make its own algo if the list is big enough (or sufficiently often filtered) for the performance suffer. A good reflection of development is to always use the same method but to do what is best.

Similar Threads

  1. How to remove multiple elements of a vector in a loop
    By PsychoVillan in forum Software Development
    Replies: 6
    Last Post: 27-06-2011, 07:27 AM
  2. How to Add and Remove HTML elements Dynamically In Javascript?
    By Level8 in forum Software Development
    Replies: 5
    Last Post: 20-02-2010, 06:48 PM
  3. DOM elements : remove with jQuery
    By Servant in forum Software Development
    Replies: 4
    Last Post: 30-01-2010, 10:32 AM
  4. Replies: 8
    Last Post: 02-01-2010, 05:53 AM
  5. Photoshop Elements and Premiere Elements go to version 7.0
    By Killen in forum Customize Desktop
    Replies: 2
    Last Post: 29-08-2008, 01:17 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,726,920,665.65306 seconds with 16 queries