Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次の文字列が与えられた場合
String a = "hello"; String b = "hell"; String c = "help";
文字列 b が a の部分文字列かどうか、文字列 c が a の部分文字列かどうかを調べたいと思います。
ここでわかるように、答えは明らかに b では「はい」、c では「いいえ」です。Java でこのテストを実行するにはどうすればよいですか?
非常に簡単:
if (a.startsWith(b))
これを試して:
if(a.contains(b)) {...} if(a.contains(c)) {...}
また動作します:
if(a.contains("ell")) {...}