myc_100 于 2012.11.05 13:08 提问

``````String st1 = "",st2 = "",st3 = "",st4 = "";
String[] str = {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";
``````

4个回答

LiDaming_and   2012.11.05 17:04

``````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"));
``````
myc_100 你是说我可以再Map中使用循环动态的设置一个值？
5 年多之前 回复
Baby_Bonnie   2012.11.06 17:29

``````Map<String,String> myKVMap=new HashMap<String,String>();
myKVMap.put("strHi","value1");
myKVMap.put("strHello","value2");
myKVMap.put("strThere","value3");
``````

znl_12   2012.11.06 17:32

``````public enum EnumModifE {
str1("1"), str2("2"), str3("3");
String value;
EnumModifE(final String s) {
this.value = s;
}
public void setValue(final String s) {
this.value = s;
}
}
public class EnumModifM {
public static void main(final String[] args) {
for (final EnumModifE eme : EnumModifE.values()) {
System.out.println(eme + "\t" + eme.value);
}
EnumModifE.str1.setValue("Hello");
EnumModifE.str2.setValue("all");
EnumModifE.str3.setValue("[wo]men");

for (final EnumModifE eme : EnumModifE.values()) {
System.out.println(eme + "\t" + eme.value);
}
}
}
``````

``````str1    1
str2    2
str3    3
str1    Hello
str2    all
str3    [wo]men
``````
yongyong_21   2012.11.06 11:19

``````Map<String,String> map = new HashMap<String,String>();
String[] str = {"hi","hello","there"};

for(int x = 0; x < str.lenght;x++){
map.put(str[x],"something you want to store");

}
``````