Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javatechie.solution;
- import java.util.ArrayList;
- import java.util.List;
- public class CustomeArrayListNotAllowDuplicate extends ArrayList {
- @Override
- public boolean add(Object o) {
- if (this.contains(o)) {
- return true;
- } else {
- return super.add(o);
- }
- }
- public static void main(String[] args) {
- List list=new CustomeArrayListNotAllowDuplicate();
- list.add(1);
- list.add(1);
- System.out.println(list);
- }
- }
Add Comment
Please, Sign In to add comment