Compare First 3 Character String with List of String of Each String First 3 Character

后端 未结 5 1286

The Sample Code which needs a solution?

public class TestJJava {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

               


        
5条回答
  •  臣服心动
    2021-01-26 07:26

    List.contain(Object o) checks if the "object" is in the list or not . In your case the objects those are in the List is String and they are "111XXXX1" , "122XXX1" and "122XXX1" . So if the following will return true only

    lstValues.contain("111XXXX1")--> true lstValues.contain("122XXX1") --> true lstValues.contain("122XXX1") --> true

    But if you do the following it will return false :

    lstValues.contain("123") --> false .

    Here is what javadoc says for List.contains(Object o)

    Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).

    So you can see it determines if the object is equal or not . So none of the items in the ArrayList matches to "123" . Therefore you will get a "No Match Found"

提交回复
热议问题