Java 我怎样才能找到索引值,或者即使数组中存在某个字符串
我尝试过使用.indexof方法,但我不明白为什么它不起作用,因为我所需要的只是查找数组中是否存在值Java 我怎样才能找到索引值,或者即使数组中存在某个字符串,java,android,Java,Android,我尝试过使用.indexof方法,但我不明白为什么它不起作用,因为我所需要的只是查找数组中是否存在值 final String subject = ((EditText)findViewById(R.id.subject)).getText().toString(); final String subjects[] ={"biology","business","chemistry","
final String subject = ((EditText)findViewById(R.id.subject)).getText().toString();
final String subjects[] ={"biology","business","chemistry","computer science","critical thinking",
"economics","english language", "english literature","further mathematics","geography",
"german","politics","history","ict","japanese","law", "mathematics","psychology",
"religious studies","sociology","spanish"};
final String creative_subjects[] ={"art and design","fine art", "dance","design and technology",
"design and textiles","fashion and textiles", "film studies ","music","performing arts",
"photography", "physical education","graphics"};
creative_subjects.indexOf(subject.toLowerCase());
数组没有很多有用的方法。但可以将数组包装为列表:
Arrays.asList(creative_subjects).indexOf(...)
Arrays.asList(creative_subjects).contains(...)
// Etc.
试试这个
String[] values = {"AB","BC","CD","AE"};
boolean contains = Arrays.stream(values).anyMatch("s"::equals);
如需进一步澄清,请访问这是否回答了您的问题?