contains
is a well-documented and a (hopefully) well-tested method of an enterprise-level software framework, which (as a rule of thumb) usually means it is working properly.
In this particular case, the contains
method is working fine. Your initial string contains $FB
, so it also contains $F
(and FB
and $
and F
and B
, if you think about it).
Maybe (and I'm making a wild guess) instead you're trying to find what's contained after the last found item. In that case, don't use contains
, use indexOf
, save the value and then search from that saved value and on.
Edit per request, here is a sample of such code. Note that I haven't tested it, so there may be some checks missing:
int currentIndex = 0;
for(String s : list) {
int foundIndex = description.indexOf(s, currentIndex);
if(foundIndex >= 0) {
System.out.println(s);
currentIndex = foundIndex + 1;
}
}