栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Java:有地图功能吗?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java:有地图功能吗?

从Java 6开始,JDK中没有函数的概念。

番石榴具有功能接口,但是该
方法提供了您所需的功能。

Collections2.transform(Collection<E>,Function<E,E2>)


例:

// example, converts a collection of integers to their// hexadecimal string representationsfinal Collection<Integer> input = Arrays.asList(10, 20, 30, 40, 50);final Collection<String> output =    Collections2.transform(input, new Function<Integer, String>(){        @Override        public String apply(final Integer input){ return Integer.toHexString(input.intValue());        }    });System.out.println(output);

输出:

[a, 14, 1e, 28, 32]

如今,在Java 8中,实际上已经有一个map函数,因此我可能会以一种更简洁的方式编写代码:

Collection<String> hex = input.stream()        .map(Integer::toHexString)        .collect(Collectors::toList);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/452886.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号