In Java is there a way to check the condition:
(在Java中有一种方法来检查条件:)
"Does this single character appear at all in string x"
(“这个单个字符是否出现在字符串x中”)
without using a loop?
(没有使用循环?)
You can use string.indexOf('a') .
string.indexOf('a')
(你可以使用string.indexOf('a') 。)
If the 'a' is present in string , it returns the index(>=0). (如果string存在'a' ,则返回索引(> = 0)。)If not, it returns -1. (如果不是,则返回-1。)So, a non-negative return value means that 'a' is present in the string . (因此,非负返回值意味着'a' is present in the string 。)
If the 'a' is present in string , it returns the index(>=0).
'a'
string
(如果string存在'a' ,则返回索引(> = 0)。)
(如果不是,则返回-1。)
'a' is present in the string
(因此,非负返回值意味着'a' is present in the string 。)
1.4m articles
1.4m replys
5 comments
57.0k users