There is a difference between list.contains() and string.contains(). That is your problem here. The first checks if there are exact matches of the whole object, while the second checks for the actual content of the strings.
Example for list.contains():
new String[]{"test", "test2", "img1"}
contains the actual string object img1 (true). If we change the array to
new String[]{"test", "test2", "clone_envx:img1"}
then it doesn't contain a perfect match (false).
Java 7 solution to the problem:
for (String str : image.getRepoTags()) {
if(str.contains(imageTag)) {
return true;
}
}
return false;
the second return should only happen after iterating the whole list. That is the reason it is after the loop.
list.contains()andstring.contains(). that is your problem here. the first checks if there are exact matches of the whole object, while the second checks for the actual content of the stringsimageTag = " clone_envx"It must return true? and It 's"tag1:tag2:tag3:img1"a valid value ofgetRepoTags()[0]?imageTag = " img"It must returntrue?