如何在字符串数组项元素内搜索特定文本?以下是 xml 文件的示例。字符串数组名称是 android.我在字符串数组中有一些项目。现在我想搜索“软件”这个词。请告诉我该怎么做?
<?xml version="1.0" encoding="utf-8"?><resources>
<string-array name="android">
<item>Android is a software stack for mobile devices that includes an operating system, middleware and key applications.</item>
<item>Google Inc. purchased the initial developer of the software, Android Inc., in 2005..</item>
</string-array>
该方法具有更好的性能:
String[] androidStrings = getResources().getStringArray(R.array.android);
if (Arrays.asList(androidStrings).contains("software") {
// found a match to "software"
}
Arrays.asList().contains()
比使用更快for
loop.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)