I'm trying to compare two lists. First list has values from switches of class1 and the other list I'm trying to retreive it from a site (class2). I'm trying to compare those two lists but if statement returns no. For example I'm checking the soy switch and when I scan a barcode the fetched list has soy in it but text returns no. Help me please!
Here is the code that I wrote. Class1
public ArrayList<String> soy2= new ArrayList<String>();
Switch soy;
.....................
if (soy.isChecked()) {
checked();
}
else {
textView.setText("blahblah");
}
public void checked() {
soy2.add("Soy");
soy2.add("Σόγια");
soy2.add("soja");
soy2.add("Soybeans");
soy2.add("soybeans");
soy2.add("en:soybeans");
//checkedAllergens.add(soy2);
}
public ArrayList<String> getList() {
return soy2;
}
Class2
public Manage checkd;
String fetchedAllergens=new String();
List<String> fetchedAllergensList = new ArrayList<String>();
.......................
public void test() {
checkd = new Manage();
ArrayList<String> list = checkd.getList();
System.out.println(list);
System.out.println(fetchedAllergensList);
if(fetchedAllergensList.contains(list))
{
testtxt.setText("yes");
}
else
{
testtxt.setText("no");
}
//Test method is calling by a click listener and i get the list from class 2 with the code below
protected String doInBackground(String... strings) {
final String barcode = strings[0];
@Nullable
String allergens = null;
try {
final String jsonStr = Jsoup.connect(
"https://world.openfoodfacts.org/api/v0/product/" + barcode + ".json")
.ignoreContentType(true)
.execute()
.body();
final JSONObject jsonObj = new JSONObject(jsonStr);
if (jsonObj.has("product")) {
JSONObject productNode = jsonObj.getJSONObject("product");
allergens = productNode.getString("allergens");
}
} catch (IOException | JSONException e) {
e.printStackTrace();
}
fetchedAllergens=allergens;
fetchedAllergensList = Arrays.asList(fetchedAllergens.split(","));
System.out.print(fetchedAllergensList);
return allergens;
}