我有一个字符串数组,其中包含智能手机中可用的传感器列表。 在这个数组中,如果有匹配项,我想要的每个元素都将替换整个字符串。
例如:
sensor[1] = "iEnemoEngine orientation sensor";
如果 sensor[1]
包含单词“orientation”,我想用“orientation”替换整个字符串“iEnemoEngine orientation sensor”
我该怎么办?
最佳答案
试试这个:
if (sensor[1].contains("orientation")) {
sensor[1] = "orientation";
}
关于java - 替换java中的整个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15631944/