我正在尝试添加要通过单个键值添加/检索的各种记录。
每条数据记录应该有如下参数;
public class WebRecord {
Integer UniqueCustomerID;
Integer Count; // Number of websites for a given customer
//Repeat the following 'Count' number of times
{ // Each Record for a given Website for the same customer
String BusinessName, Websites, siteTag;
Integer uniqueWebID, BusinessTypeID;
}
}
我希望此类记录基于我从 Web 服务获得的计数值而存在。 我打算按如下方式使用 Hashmap:
有人能告诉我如何在 HASHMAP 中实现该数据结构吗? 我想使用单个键值 UniqueCustomerID 放置和获取这些记录;
最佳答案
不擅长 java 概念,但我认为你可以做到,
class WebRecord{
int UniqueCustomerID;
int Count;
}
class ContactRecord{
String BusinessName, Websites, siteTag;
int uniqueWebID, BusinessTypeID;
}
在你的 java 文件中
MyActivity{
public Map<WebRecord,ArrayList<ContactRecord>> map=new HashMap<WebRecord,ArrayList<ContactRecord>>();
//now create one object of web record
//create arraylist of ContactRecord depending upon "count" variable's value
// fill the above both and put into map
map.put(webRec, arrContact);
}
关于java - 如何将不同类型的对象添加到 Android 中的 HashMap 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10458762/