当前位置: 首页 > 面试题库 >

如何使哈希表Arraylist达到其他目的?

薄烨
2023-03-14
问题内容

我在数组列表中有hashbles。

 List<Hashtable<String, String>> info = new ArrayList<Hashtable<String, String>>();


 Hashtable<String, String> hm = new Hashtable<String, String>();
// Put elements to the map

hm.put("Read_Flag", s1);
hm.put("sms_received_id", s2);
hm.put("Sender_Id", s3);
hm.put("Sender_Name", s4);
hm.put("Patient_Name", s5);
hm.put("Received_Date", s6);
hm.put("Received_Text", s7);
hm.put("Received_Text_Full", s8);
hm.put("AttachmentFlag", s9);

// Get a set of the entries
Set<?> set = hm.entrySet();
// Get an iterator
Iterator<?> it = set.iterator();
// Display elements
while(it.hasNext()) {
Map.Entry me = (Map.Entry)it.next();
 // System.out.print(me.getKey() + ": ");
 // System.out.println(me.getValue());
}
//System.out.println(hm);

info.add(hm);

这里的信息包含我的哈希表。我如何才能将此“信息”对象转换为其他类/意图?

谢谢…


问题答案:

创建一个延伸的类Serializablegetter setterList<Hashtable<String, String>> list

Custom.java

public class Custom implements Serializable{

    private static final long serialVersionUID = 4466821913603037341L;
    private List<Hashtable<String, String>> list;


    public List<Hashtable<String, String>> getList() {
        return list;
    }

    public void setList(List<Hashtable<String, String>> list) {
        this.list = list;
    }
}

传递到下一个活动。

List<Hashtable<String, String>> list = new ArrayList<Hashtable<String,String>>();

Custom custom = new Custom();
custom.setList(list);
intent.putExtra("myobj", custom);

在下一个活动中检索

Intent intent = getIntent();
Custom custom = (Custom) intent.getSerializableExtra("myobj");
List<Hashtable<String, String>> list = custom.getList();


 类似资料:
  • 我刚刚开始学习哈希表,我知道如何插入,但不知道如何搜索。以下是我将基于这个问题的算法: 散列密钥 线性探测碰撞分辨率。 假设我用键1、11和21调用两次插入。这将返回所有3个键的槽1。冲突解决后,表在槽1、2和3处将有值1、11和21。这就是我对插入的理解。 完成此操作后,如果搜索键11和21,我将如何获得插槽2和3?从我所读到的内容来看,搜索哈希表应该做与插入完全相同的事情,除非当你到达所需的插

  • 问题内容: 当大小超过maxthreshold值时,如何在哈希表或哈希表中进行重新哈希处理? 是否所有对都已复制到新的存储桶阵列中? 编辑: 重新哈希后,同一存储桶(位于链接列表中)中的元素会发生什么情况?我的意思是说,他们在重新哈希处理后会留在同一个桶中吗? 问题答案: 问题中的最大阈值称为负载系数。 建议负载系数约为0.75。负载因子定义为(m / n),其中n是哈希表的总大小,m是在需要增加

  • 问题内容: 我有一百万行.txt格式的数据。格式很简单。对于每一行: 你知道我的意思。对于每个用户,它可能出现很多次,或者只出现一次(您永远不会知道)。我需要找出每个用户的所有值。因为用户可能会随机出现,所以我使用了Hashmap来做到这一点。即:HashMap(键:字符串,值:ArrayList)。但是要向arrayList添加数据,我必须不断使用HashMap get(key)来获取array

  • REDIS_HASH (哈希表)是 HSET 、 HLEN 等命令的操作对象, 它使用 REDIS_ENCODING_ZIPLIST 和 REDIS_ENCODING_HT 两种编码方式: 字典编码的哈希表 当哈希表使用字典编码时, 程序将哈希表的键(key)保存为字典的键, 将哈希表的值(value)保存为字典的值。 哈希表所使用的字典的键和值都是字符串对象。 下图展示了一个包含三个键值对的哈希

  • Hashtbl 模块 Hashtbl模块实现了一个高效的,可变的查询表。如下创建一个哈希表: # let my_hash = Hashtbl.create 123456;; val my_hash : ('_weak1, '_weak2) Hashtbl.t = <abstr> 这个123456是哈希表的初始大小。这个值可以是你对数据量的一种猜测,但是哈希表有可能会 随着数据量的增多而变大,因此

  • 哈希表 通过最简单的取模运算作为哈希算法 class HashNode(object): def __init__(self, id, data): self.id = id self.data = data self.next = None def __str__(self): return '(%d,%s)' %