i am new to Java. i want to convert string to HashMap. but i dont know how to convert it. below is my code.
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);
}
}
my input :
“u1”,“u10”
“u2”,“u41”
“u3”,“u10”
“u4”,“u81”
“u5”,“u10”
“u6”,“u10”
“u7”,“u31”
“u8”,“u11”
my output of string("v value") :
“u1” “u10” “u2” “u41” “u3” “u10” “u4” “u81” “u5” “u10” “u6” “u10” “u7” “u31” “u8” “u11”
i need to convert this string(v Value) into HashMap<string,String>(like key,value pair).how to do that?
can anyone help to find solution please?