【发布时间】:2014-09-27 17:59:45
【问题描述】:
我是 Java 新手。我想将字符串转换为HashMap。但我不知道如何转换它。下面是我的代码。
public class Excer5sam {
public static void main(String[] args) throws IOException{
BufferedReader fl=new BufferedReader(new FileReader("/home/mansoor/Documents/Fileip.txt"));
Map<String, String>map=new HashMap<String, String>();
List<String>str=new ArrayList<>();
String ln=null;
while((ln=fl.readLine())!=null){
str.add(ln);
}
fl.close();
String s="";
for(String s1:str){
s+=s1+",";
}
System.out.println("value of s:"+s);
String v=s.replace(",", " ");
System.out.println("v value:"+" "+v);
}
}
我的意见:
“u1”,“u10”
“u2”,“u41”
“u3”,“u10”
“u4”,“u81”
“u5”,“u10”
“u6”,“u10”
“u7”,“u31”
“u8”,“u11”
我的字符串输出(“v值”):
“u1”“u10”“u2”“u41”“u3”“u10”“u4”“u81”“u5”“u10”“u6”“u10” “u7” “u31” “u8” “u11”
我需要将此string(v Value) 转换为HashMap<string,String>(如键、值对)。怎么做?
谁能帮忙解决一下?
【问题讨论】: