`

List to Map

 
阅读更多
/**
* <p>将List变为Map</p>
* @param list
* @param <V> list的项目
* @param keyField 作为Map的项目
* @return 变换成的Map
* @throws Exception keyField项目没有找到的话,抛出异常
*/
private <V> Map<String, V> c(List<V> list, String keyField) throws Exception {

Map<String, V> map = new HashMap<String, V>();

for (V obj : list) {
String key = BeanUtils.getProperty(obj, keyField);
map.put(key, obj);
}
return map;
}
分享到:
评论

相关推荐

    js模拟list和map

    javascript 模拟 java中的 List,Map js文件为 js/utils.js IE6.0 测试通过 &lt;br&gt;List: add(var obj) //添加一个元素 remove(var index) //删除一个元素 get(var index) //获取一个元素 remove...

    Java中 List《map》把里面map中某个key相同记录的其他key 的 value 合并

    Java中 List《map》把里面map中某个key相同记录的其他key 的 value 合并 Java中 List《map》把里面map中某个key相同记录的其他key 的 value 合并

    在Java 8中将List转换为Map对象方法

    主要介绍了在Java 8中将List转换为Map对象方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

    Google转Map图层

    Google转Map图层

    StringtoList和StringtoMap和StringtoObject和StringtoArray

    Json格式的字符串转成List、Array、Map、Object、List等,就是各种字符串转其他格式的方法.有个封装好的转换方法和一个我自己做的示例

    json字符串转成 Map/List

    NULL 博文链接:https://wuniu2010.iteye.com/blog/1771934

    list转String

    String list 转化为 String, 使用Stringbuffer 。。。。。。。。。。。。。。。

    驼峰处理,map过滤

    查询返回map或list&lt;Map&gt;时,针对大小写以及下划线,横杠(USER_NAME,USER-NAME),转化为标准的java变量类型userName,支持互相转化。

    map 和 bean 之间的转换

    map 和 bean 之间的转换,可以利用反射的原理实现

    jackson json 转 map 数值科学计数法的问题解决.docx

    将json转换为map之后,如果数值类型太多会在转换之后出现科学计数法的问题,经研究jackson源码、网上百度资料得知可以通过设置一些参数解决该问题

    Map to List

    NULL 博文链接:https://cxwitjy.iteye.com/blog/1456617

    java面试宝典

    192、Can I use Hidden form field to track session? 45 194、In a architecture pattern like MVC, it is mandatory that Servlet should be the controller, why not JSP? 46 195、Why JSP is used as View part ...

    unordered-list-to-mind-map:使用kityminder-core将html无序列表转换为思维导图的示例

    unordered-list-to-mind-mapAn example that converts html unordered list to mind map using kityminder-core使用百度脑图的 kityminder-core,将 HTML 无序列表转换为思维导图的示例How to UseYou will find the ...

    python 基础教程之Map使用方法

    Map的规范为:map(function_to_apply, list_of_inputs) 大多数时候,我们需要将列表中的所有元素一个个传递给一个函数,并收集输出。例如: items = [1, 2, 3, 4, 5] squared = [] for i in items: squared....

    jdk1.8.0_202.zip

    java 开发者 配置jdk1.8 一下是jdk1.8的... List&lt;Integer&gt; c = names.stream.map(x-&gt;x.length()).collect(Collectors.toList()); List&lt;Integer&gt; c = names.stream.map(String::length).collect(Collectors.toList());

    RoadMapiOS.pdf 苹果官方

    the last tutorial, you’ll have created a simple to-do list app. After you’ve built your first app in this guide and are considering your next endeavor, read the fourth module. It explores the ...

    Java中快速把map转成json格式的方法

    主要介绍了Java中快速把map转成json格式的方法,本文使用json-lib.jar中的JSONSerializer.toJSON方法实现快速把map转换成json,需要的朋友可以参考下

    POJ 1002 487-3279 telephone numbers

    A, B, and C map to 2 D, E, and F map to 3 G, H, and I map to 4 J, K, and L map to 5 M, N, and O map to 6 P, R, and S map to 7 T, U, and V map to 8 W, X, and Y map to 9 There is no mapping for...

    lodash underscore js库速查手册

    _.each(list, iterator, [context]) Alias: forEach Iterates over a list of elements, yielding each in turn to an iterator function. The iterator is bound to the _.map(list, iterator, [context]) Alias: ...

    java实现多层嵌套循环参数转换

    多层嵌套循环 参数转换 数据库配置报文父子级结构 java实现

Global site tag (gtag.js) - Google Analytics