Bundle是一种利用键值对存储的数据格式,而我们在程序中通常利用HashMap存储数据。在开发中,通过Http请求得到JSONArray类型的返回值,我选择利用ArrayList<HashMap<String, String>>格式存储JSONArray对象。Bundle对象中putParcelabelArrayList方法可以将ArrayList格式数据传入Bundle,用于Intent在不同activity中传递。因此需要一种将ArrayList<HashMap<String, String>>格式转为ArrayList<Bundle>格式的方法。

下面就贴出我实现的方法:

     /**
* ArrayList中存储的Hashmap转为bundle
* @param list
* @return
*/
public static ArrayList<Bundle> Map2Bundle(ArrayList<HashMap<String, String>> list){
ArrayList<Bundle> bundleList = new ArrayList<>();
for(HashMap map : list) {
Bundle bundle = new Bundle();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry)iter.next();
Object key = entry.getKey();
Object value = entry.getValue();
bundle.putString(String.valueOf(key), String.valueOf(value));
}
bundleList.add(bundle);
}
return bundleList;
}

这里遍历HashMap时采用的是效率最高的迭代器。欢迎大家多多批评指正!

将ArrayList<HashMap<String, String>>转为ArrayList<Bundle>类型的解决方案的更多相关文章

  1. 自己写的demo。List<HashMap<String,Object>>=new ArrayList<HashMap<String,Object>>

    package com.pb.collection; import java.util.ArrayList; import java.util.HashMap; import java.util.It ...

  2. Junit + String/Integer/ArrayList/HashMap/TreeMap 基本使用Demo

    package JavaTest.test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; ...

  3. ArrayList<HashMap<String,Object>>集锦

    1.   Android中如何从一个Activity中ArrayList<HashMap<String,Object>>传递到另一个activity?      eg:     ...

  4. 当List<String> list =new ArrayList<String>(20); 他会扩容多少次

    当List<String> list =new ArrayList<String>(20); 他会扩容多少次?A 0       B 1 C 2 D 3答案是A: 因为这个集合 ...

  5. 第56节:ArrayList,LinkedList和String

    import java.util.ArrayList; public class Demo{ public static void main(String[] args) throws Excepti ...

  6. ArrayList集合、String[]数组、String字符串

    数组初始化时候必须指定长度,而ArrayList是动态数组,可以根据实际内容改变 //声明stsArr数组并初始化 String[] strArr = new String[]{ "aaa& ...

  7. List<String> list=new ArrayList<String>(20);为什么要声明为List 而不是ArrayList<String>?

    如何理解:List<String> list=new ArrayList<String>();为甚麼要声明为List 而不是ArrayList<String>? 在 ...

  8. Java--泛型理解和使用 (List<String> list = new ArrayList<String>(); )

    List<String> list = new ArrayList<String>(); 第一次看到这行代码是一头雾水,查了好久才弄清楚这是什么东西,怎么用,所以记录下来,方便 ...

  9. 面试6 --- 当List<String> list =new ArrayList<String>(20); 他会扩容多少次

    当List<String> list =new ArrayList<String>(20); 他会扩容多少次?A 0       B 1 C 2 D 3答案是A: 因为这个集合 ...

随机推荐

  1. 开涛spring3(5.1&5.2) - Spring表达式语言 之 5.1 概述 5.2 SpEL基础

    5.1  概述 5.1.1  概述 Spring表达式语言全称为“Spring Expression Language”,缩写为“SpEL”,类似于Struts2x中使用的OGNL表达式语言,能在运行 ...

  2. Fiddler中如何抓取app中https(443端口)数据

    Fiddler不但能截获各种浏览器发出的HTTP请求, 也可以截获手机发出的HTTP/HTTPS请求,总结下Fiddler截获IPhone和Android发出的HTTP/HTTPS包,前提条件是:安装 ...

  3. reshape: from long to wide format(转)

    This is to continue on the topic of using the melt/cast functions in reshape to convert between long ...

  4. 总结scala(一)

    由于笔记太多,分为了几部分,进入我的博客,查看其它的笔记 scala:面向对象,函数式编程 一.声明变量 1.变量的类型 Byte,Char,Short,Int,Long,Float,Double,B ...

  5. 互联网“剁手”新方向,VR全景购物忙——全景智慧城市常诚

    随着VR和AR技术的兴起,各行各业都在寻求VR+的对接方式,除了游戏和社交平台,另一大对VR有着浓厚兴趣的就是电商平台了,阿里.京东等电商巨头纷纷成立VR事业部,如何让亿万用户在VR中愉快的买买买,已 ...

  6. Java对【JSON数据的解析】--官方解析法

    要求:解析下面5个JSON数据 1.String string ="{name:'zhangsan',age:18}"; 2.String string2 = "{per ...

  7. canvas——随机生成迷宫

    先上图. 效果 代码 随机生成迷宫要求任意两点都能够找到相同的路径,也就是说,迷宫是一个连通图.随机生成迷宫可以使用普里姆算法.广度优先算法.深度优先算法等实现.这里将使用普里姆算法通过生成最小数的方 ...

  8. Postgres Linux 维护 随笔1(启动篇)

    关于postgres 起停操作随笔 Linux 环境下,对Postgres 起停常用代码 Postgres 启动 : pg_ctl start Postgres 停止 : pg_ctl stop Po ...

  9. charles连接手机抓包

    写给我自己: 如果是使用charles抓包.一定要tm的保证手机和电脑连的是一个网. 1.proxy setting,查看charles,端口 2.勾选 3.ipconfig,查看自己电脑的ip地址 ...

  10. js禁止浏览器的回退事件

    直接来个终极方案: 查找了好多资料才找到的,这种方式,可以消除 后退的所有动作.包括 键盘.鼠标手势等产生的后退动作. <script language="javascript&quo ...