我想知道是否可以将字符串变量存储在字符串数组中?我无法很好地解释它,但这是我所做的:
String st1 = "",st2 = "",st3 = "",st4 = "";
String[] str = {st1,st2,st3,st4};
很不幸,当我使用for循环时,字符串获取的是st1、st2、st3和st4的值,而不是变量本身。
这正是我想要在我的脑海中实现的。无论何时,例如当我有一个字符串数组:
String[] containsValue = { "hi", "hello", "there" };
String strHi, strHello, strThere;
String[] getContainsValue = { strHi, strHello, strThere };
for (int x = 0; x < getContainsValue.length; x++) {
getContainsValue[x] = containsValue[x];
}
The value of:
strHi = "hi"
strHello = "hello"
strThere = "there";
基本上,我想将containsValue []的值转移到存储在getContainsValue []中的三个字符串strHi,strHello,strThere中。然后使用for循环将来自containsValue []的值分配给它们。
这可能吗?如果是这样,请您提供一些如何执行此操作的格式。谢谢。
.lenght
当然应该是.length
... - Ben