-2
我想打印对象值。 我无法访问它,不知道如何去做。如何从Java中的HashMap获取值?
我不能与value()
这里接取这是我的代码:
public class txtdatei {
private String pickerName;
private String language;
private float volumeGain;
private long pickerId;
private static Map<Long,txtdatei> mapp=new HashMap<Long,txtdatei>();
public txtdatei(String username, String language, float volume){
this.pickerName=username;
this.language=language;
this.volumeGain=volume;
}
public static void main(String[] args){
File file=new File("test.txt");
try{
file.createNewFile();
FileWriter writer =new FileWriter(file);
writer.write("username\tbenni\tlanguage\tgerman\n");
writer.flush();
writer.close();
FileReader fr =new FileReader("test.txt");
BufferedReader reader= new BufferedReader(fr);
String zeile=reader.readLine();
String [] data=zeile.split("\t");
int i=0;
for(i=0;i<data.length;i++)
{
if(data[i].equals("Username"))
{
mapp.put((long)(1),new txtdatei(data[2],data[4],Float.parseFloat(data[6])));
}
}
System.out.println(mapp.get(1)); //dont know how to read the
}catch(IOException ioe){ioe.printStackTrace();}
}
希望有人能帮助我,
感谢。
你有没有听说过使用[为地图的JavaDoc](https://docs.oracle.com/javase/7/docs/api/java/util/Map.html的)?看看'Map.get(key)'。 –
此外,你写'用户名',但等于检查'用户名'。 –