Skip to main content

Command Palette

Search for a command to run...

Java : How to find Array list contains Duplicate ?

Published
1 min read
S

I love learning about technology and sharing that with others

Introduction

Here we are having the data in the arraylist and if the arraylist contains any duplicate element in that case we need to check the duplicate .

Fix : Store all the ArrayList in the hashset and then check the size of the hashset should be smaller than the arraylist if this is true then duplicate is present

columnname list a arraylist of type String.

Set<String> set=new HashSet<>(columnNameList);
         if(set.size() < columnNameList.size()){
             //if set size is smaller means arraylist contains duplicate
                return true;
            }
2 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)