java如何在安卓中向另一个字符串数组添加字符串?
这是我的java代码,这里我必须在一个字符串数组itemtypes中添加一个字符串“RFID”,并将其存储在另一个字符串数组项中。但是我犯了一个错误
String[] itemtype;
String[] item;
\...........
.........../
try {
response = (SoapPrimitive) envelope.getResponse();
Koradcnos = response.toString();
} catch (SoapFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
itemtypes = Koradcnos.split(";");
item=itemtypes+"RFID";//here im getting error
} catch (Exception er) {
//Helper.warning("Error", er.toString(),this);
}
imageId = new int[itemtypes.length];
for (int i = 0; i < itemtypes.length; i++)
if (itemtypes[i].equals("Yarn")) {
imageId[i] = R.drawable.yarnitem;
# 1 楼答案
你需要解决这个问题:
与
Arrays.copyOf
一起使用或者直接从
Koradcnos
拆分# 2 楼答案
itemtypes
是字符串数组,它不能被修改,如果你想得到一个新的数组添加另一个元素,你可以使用System.arrayCopy像这样:
# 3 楼答案
不能将字符串与列表连接
String.split()
方法返回字符串数组而不是
item=itemtypes+"RFID"
遍历数组,如下所示:此外,我认为变量名将是
itemtypes
,而不是itemtype