How can I check if a String
is there in the List
?
I want to assign 1
to temp
if there is a result, 2
temp = bankAccNos.contains(no) ? 1 : 2;
The List
interface already has this solved.
int temp = 2;
if(bankAccNos.contains(bakAccNo)) temp=1;
More can be found in the documentation about List.
List list1 = new ArrayList();
list1.add("one");
list1.add("three");
list1.add("four");
List list2 = new ArrayList();
list2.add("one");
list2.add("two");
list2.add("three");
list2.add("four");
list2.add("five");
list2.stream().filter( x -> !list1.contains(x) ).forEach(x -> System.out.println(x));
The output is:
two
five