How to find Duplicate Entry of Elements (numbers) in ArrayList in java

How to find Duplicate Entry of Elements (numbers) in ArrayList in java
SOURCE : NumDuplicate.java

import java.util.ArrayList;
import java.util.List;

public class NumDuplicate {

static void dups(List ls) {

List lst = new ArrayList<>();

for (Integer i : ls) {

if (lst.contains(i)) {

System.out.println("duplicate " + i);
} else

lst.add(i);

}
}

public static void main(String[] args) {
List ls = new ArrayList<>();
for (int i = 0; i < 30; i++) {
ls.add(i);
}
ls.add(15);
ls.add(22);
dups(ls);

}

}


INPUT

number from 1 to 30 and
added 15 and 22 as duplicate



OUTPUT

duplicate 15
duplicate 22








Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment