simple conditional in java (unexpected issue)

前端 未结 3 1617
不知归路
不知归路 2021-01-29 14:52

I have an unexpected issue when using a conditional operator in java. The code is supposed to check if the ArrayList contains a specific string, then it returns tru

3条回答
  •  野性不改
    2021-01-29 15:47

    When you use a1.contains(...), you are checking if any sting in array is ".". This is different from your intention to check if any string in array "a1" contains '.' char as I understand.

    If you need to check if any string in array contains "." text it can be like this:

    for(String text : a1) {
      if(text != null && text.indexOf(".") >= 0) {
        return false;
      }
    }
    return true;
    

提交回复
热议问题