Question: how to check if a string contains only certain characters in java?
Answer: // set of characters to be searched char[] chSearch = {'p', 'q', r'}; For this, loop through the length of the string and check every character in the string “str”. If the matching character from “chSearch” is found in the string, then it would be a success.