Java (ArrayList check with object's int) -


i have make arraylist contains object, object has 1 int year lets 1 , don't object same year 1.

if 1 object has int = 1 , dont want object int(1) in list. want deny it.

should try using equal?

something

@override public boolean equals(object o){     object object = (object)o;     return this.getint.equals(object.getint()); } 

either use set...which explicitly disallows duplicates, or check if list contains element on insertion.

@override public boolean add(t element) {     if(contains(element)) {         return false;     } else {         return super.add(element);     } } 

overriding equals wouldn't far, you'd overriding list (i.e. you'd checking if 2 lists equal).


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -