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
otherwise.
My current code is:
Integer temp = 0; List<String> bankAccNos = new ArrayList<String>();//assume list contains values String bankAccNo = "abc"; for(String no : bankAccNos) if(no.equals(bankAccNo)) temp = 1;
Advertisement
Answer
temp = bankAccNos.contains(no) ? 1 : 2;