Reputation: 95
Given the following strings
String a = "hello";
String b = "hell";
String c = "help";
I would like to find out if string b is a substring of a, and if string c is a substring of a.
You can see here the answer is clearly yes for b and no for c. How can I perform this test in Java?
Upvotes: 0
Views: 114
Reputation: 340733
Try this:
if(a.contains(b)) {...}
if(a.contains(c)) {...}
works also with:
if(a.contains("ell")) {...}
Upvotes: 2