Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Remove duplication from array list

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 298
    Comment on it

    If you want to remove duplicate entries from your array list you can use hash set to make all items unique rather than use of algorithms.

    Set is a ordered collection of items and contains only unique items. And Hashset creates a collection that uses a hash table for storage. It stores items by using Hashing maintain key for each items and remove duplication.

       Set<String> hsName = new HashSet<>();
            Set<String> hsId = new HashSet<>();
    
            ArrayList<String> alName = new ArrayList<>();
            ArrayList<String> alId = new ArrayList<>();
    
            for (int i = 0 ; i< yourList.size();i++){
                alName.add(yourList.get(i).getSkillName());
                alId.add(yourList.get(i).getSkillId());
    
            }
    
            hsName.addAll(alName);
            alName.clear();
            alName.addAll(hsName);
    
            hsId.addAll(alId);
            alId.clear();
            alId.addAll(hsId);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: