+ 3
I need some help .. How can i check that if ArrayList contains the element or not?
How can i avoid duplicated items on the Arraylist note: items comes from sqlite. and passed from arraylist1 to arraylist2 ..
8 Answers
+ 4
//I am posting link because, you can see demo code as well as explication too
https://www.mkyong.com/java/java-check-if-array-contains-a-certain-value/
+ 3
Thank you Shudarshan Rai đ Denise RoĂberg I'll see them .
+ 3
Edrees
But you can add a getter to your class:
public void getStr(){
return str;
}
In your main class:
ArrayList<String> a = new ArrayList<>();
Data b = new Data("M");
a.add(b.getStr);
+ 3
it is just a small example.
The complete model contains (name,id,Bitmap,amount,etc)..
Ithink i can get names to ArrListOf String As mentioned before then check if contains or not
+ 2
An ArrayList has a contains() method. https://www.tutorialspoint.com/java/util/arraylist_contains.htm
But I think it is better to use a HashSet. In this kind of list you can not add duplicates.
https://www.sololearn.com/learn/Java/2182/?ref=app
+ 2
It worked when i add String class directly like that ArrayList list = new ArrayList<String..its ok but>();
I think contains method can't read from model As ArrayList<data contains strings too>();
Check this :
https://code.sololearn.com/c3IjFUH8VGU7/?ref=app
+ 2
Edrees
The problem is you don't add Strings to your List.
Write: System.out.println(a) to see what is really inside your list.
Edit:
Data is an object. "M" is a String. So contains("M") = false.
+ 2
I got it .. only Addresses