Check if a String is in an ArrayList of Strings

后端 未结 3 905
感情败类
感情败类 2020-12-14 14:31

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

相关标签:
3条回答
  • 2020-12-14 14:41
    temp = bankAccNos.contains(no) ? 1 : 2;
    
    0 讨论(0)
  • 2020-12-14 14:47

    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.

    0 讨论(0)
  • 2020-12-14 14:57
        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
    
    0 讨论(0)
提交回复
热议问题