哈希表来getkey哈希表来、getkey

2023-09-04 23:08:48 作者:国际男王

嘿,大家好我想提出哈希表的关键,在随后的EditText显示我的价值在TextView中

 的Hashtable<字符串,整数> HT =新的Hashtable<字符串,整数>();
//枚举<字符串> ENM;
ht.put(rakan,100);
ht.put(艾哈迈德,200);
ht.put(卫生部,3000);


迭代器<字符串> myVeryOwnIterator = ht.keySet()迭代器()。
而(myVeryOwnIterator.hasNext()){
    字符串键=(字符串)myVeryOwnIterator.next();
    整数值=(整数)ht.get(密钥);
    Toast.makeText(getBaseContext(),关键:+键+值:+值,Toast.LENGTH_LONG).show();
}


//(TextView)findViewById(R.id.tvShowValue).setTex(Integer.valueOf(+key));

//enm=ht.keys();
INT的id =的Integer.parseInt(((EditText上)findViewById(R.id.etPutKey))的getText()的toString());
((TextView中)findViewById(R.id.tvShowValue))的setText(Integer.valueOf(ID))。
 

解决方案

 字符串键=((的EditText)findViewById(R.id.etPutKey))。gettext的()。的toString() );
((TextView中)findViewById(R.id.tvShowValue))的setText(将String.valueOf(ht.get(键)));
 

阿里Java二面经典必问考点题 Redis为什么那么快

hey guys i want to put key of hashtable in the edittext then show me the value in the textview

Hashtable<String, Integer> ht=new Hashtable<String, Integer>();
//Enumeration<String> enm; 
ht.put("rakan", 100);
ht.put("ahmad", 200);
ht.put("moh", 3000);


Iterator<String> myVeryOwnIterator = ht.keySet().iterator();
while(myVeryOwnIterator.hasNext()) {
    String key=(String)myVeryOwnIterator.next();
    Integer value=(Integer)ht.get(key);
    Toast.makeText(getBaseContext(), "Key: "+key+" Value: "+value , Toast.LENGTH_LONG).show();
}


//(TextView)findViewById(R.id.tvShowValue).setTex(Integer.valueOf(+key));

//enm=ht.keys();
int id= Integer.parseInt(((EditText)findViewById(R.id.etPutKey)).getText().toString());
((TextView)findViewById(R.id.tvShowValue)).setText(Integer.valueOf(id));

解决方案

String key = ((EditText)findViewById(R.id.etPutKey)).getText().toString());
((TextView)findViewById(R.id.tvShowValue)).setText(String.valueOf(ht.get(key)));

相关推荐