How to check a String value to know in its's contain the specific letter in java? -
i want check string value know if contains exact match, not characters.
i'm searching in computer
string computer = ("monitor" + "\n" + "case" + "\n" + "mouse" + "\n" + "hard" + "\n" + "vga" + "cpu");
for exact match myletter:
string myletter = "monitor";
as opposed partial match i.e. in above case "mo", should return false.
boolean state = computer.contains("mo"); boolean state = computer.contains(myletter);
i think need use word boundaries so:
pattern p = pattern.compile(".*\\b" + myletter +"\\b.*"); matcher m = p.matcher(computer); boolean b = m.find(); system.out.println(b);
Comments
Post a Comment