我想知道是否可以在String数组上存储String变量?我不能很好地解释它,但这是我做的:
String st1 = "",st2 = "",st3 = "",st4 = "";
String[] str = {st1,st2,st3,st4};
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我使用for循环时,str获取st1和st2以及st3和st4的值而不是它自己的变量..
这就是我想要完全按照我的想法做的事情.每当有一个String数组时,例如:
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";
Run Code Online (Sandbox Code Playgroud)
基本上我想将containsValue []的值传递给3个String,它是存储在getContainsValue []中的strHi,strHello,strThere.然后使用for循环来对它们赋值来自containsValue [].这是真的吗?如果是这样,那么你可以给我一些格式怎么做?谢谢..
ada*_*ost 10
你可以用Map<K,V>.
Map<String,String> map=new HashMap<String,String>();
map.put("strHi","hi");
map.put("strHello","hello");
map.put("strThere","there");
System.out.println(map.get("strHello"));
Run Code Online (Sandbox Code Playgroud)