當前位置: 首頁>>代碼示例>>Java>>正文


Java Collectors.toMap方法代碼示例

本文整理匯總了Java中java.util.stream.Collectors.toMap方法的典型用法代碼示例。如果您正苦於以下問題:Java Collectors.toMap方法的具體用法?Java Collectors.toMap怎麽用?Java Collectors.toMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.stream.Collectors的用法示例。


在下文中一共展示了Collectors.toMap方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildTreeMapCollector

import java.util.stream.Collectors; //導入方法依賴的package包/類
/**
 * Return a Collector that collects to a TreeMap using the supplied key and value mappers. Duplicate keys will
 * result in a {@link RuntimeException}. Useful for creating sorted maps to go into HealthCheck detail values
 */
static <T, K, U> Collector<T, ?, TreeMap<K, U>> buildTreeMapCollector(
        Function<? super T, ? extends K> keyMapper,
        Function<? super T, ? extends U> valueMapper) {

    return Collectors.toMap(
            keyMapper,
            valueMapper,
            (v1, v2) -> {
                throw new RuntimeException(String.format("Duplicate key for values %s and %s", v1, v2));
            },
            TreeMap::new);
}
 
開發者ID:gchq,項目名稱:stroom-stats,代碼行數:17,代碼來源:HasHealthCheck.java

示例2: collectToBiMap

import java.util.stream.Collectors; //導入方法依賴的package包/類
public static <T, K, U> Collector<T, ?, BiMap<K, U>> collectToBiMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) {
    Collector<T, ?, BiMap<K, U>> x = Collectors.toMap(
            keyMapper, valueMapper,
            (u, v) -> {
                throw new RuntimeException("should not hapen: " + u + " --- map: " + v);
            },
            HashBiMap::create);
    return x;
}
 
開發者ID:SmartDataAnalytics,項目名稱:SubgraphIsomorphismIndex,代碼行數:10,代碼來源:SubgraphIsomorphismIndexImpl.java

示例3: toMap

import java.util.stream.Collectors; //導入方法依賴的package包/類
public static <K, U, M extends Map<K, U>> Collector<Map.Entry<K, U>, ?, M> toMap(Supplier<M> mapSupplier) {
    return Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, throwingMerger(), mapSupplier);
}
 
開發者ID:upperlevel,項目名稱:uppercore,代碼行數:4,代碼來源:CollectionUtil.java

示例4: toLinkedMap

import java.util.stream.Collectors; //導入方法依賴的package包/類
public static <T, K, U> Collector<T, ?, Map<K, U>> toLinkedMap(Function<? super T, ? extends K> keyMapper,
                                                               Function<? super T, ? extends U> valueMapper) {
    return Collectors.toMap(keyMapper, valueMapper, (u, v) -> {
        throw new IllegalStateException(String.format("Duplicate key %s", u));
    }, LinkedHashMap::new);
}
 
開發者ID:Lambda-3,項目名稱:Stargraph,代碼行數:7,代碼來源:SCollectors.java

示例5: entriesToMap

import java.util.stream.Collectors; //導入方法依賴的package包/類
public static <K, U> Collector<Map.Entry<K, U>, ?, Map<K, U>> entriesToMap() {
    return Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue);
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:4,代碼來源:Maps.java

示例6: pairsToMap

import java.util.stream.Collectors; //導入方法依賴的package包/類
public static <A,B> Collector<Pair<A,B>,?,Map<A,B>> pairsToMap(){
	return Collectors.toMap(Pair::getLeft, Pair::getRight);
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:4,代碼來源:StreamTool.java

示例7: entriesToMap

import java.util.stream.Collectors; //導入方法依賴的package包/類
public static <A,B> Collector<Entry<A,B>,?,Map<A,B>> entriesToMap(){
	return Collectors.toMap(Entry::getKey, Entry::getValue);
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:4,代碼來源:StreamTool.java

示例8: entriesToMap

import java.util.stream.Collectors; //導入方法依賴的package包/類
public static <K, U> Collector<Map.Entry<K, U>, ?, Map<K, U>> entriesToMap() {
    return Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue());
}
 
開發者ID:ohpauleez,項目名稱:dais,代碼行數:4,代碼來源:Maps.java

示例9: map

import java.util.stream.Collectors; //導入方法依賴的package包/類
/**
 * Returns a {@code Collector} that accumulates the input elements into a new {@code LinkedHashMap}.
 *
 * @param keyTransformation   the transformation function used to derive a resulting entry key from each item
 * @param valueTransformation the transformation function used to derive a resulting entry value from each item
 * @param <T>                 the type of the input elements
 * @param <K>                 the type of the output map keys
 * @param <V>                 the type of the output map values
 * @return a new collector that accumulates the input elements into a new {@code LinkedHashMap}
 * @see #map()
 */
public static <T, K, V> Collector<T, ?, Map<K, V>> map(Function<? super T, ? extends K> keyTransformation,
                                                       Function<? super T, ? extends V> valueTransformation) {

	BinaryOperator<V> merger = throwingMerger();

	return Collectors.toMap(keyTransformation, valueTransformation, merger, New::map);
}
 
開發者ID:essentials4j,項目名稱:essentials4j,代碼行數:19,代碼來源:To.java

示例10: toMap

import java.util.stream.Collectors; //導入方法依賴的package包/類
/**
 * Collects a stream of pairs into a map
 * @param <K> the left type of the pair, interpreted as the key type
 * @param <V> the right type of the pair, interpreted as the value type
 * @return a Collector which collects a Stream of Pairs into a Map
 */
static <K, V> Collector<Pair<K, V>, ?, Map<K, V>> toMap() {
    return Collectors.toMap(Pair::left, Pair::right);
}
 
開發者ID:unruly,項目名稱:control,代碼行數:10,代碼來源:Maps.java

示例11: entriesToMap

import java.util.stream.Collectors; //導入方法依賴的package包/類
/**
 * Converts entries to map.
 *
 * @param <K> Key type
 * @param <V> Value type
 * @return a collector
 */
public static <K, V> Collector<Entry<K, V>, ?, Map<K, V>> entriesToMap() {
  return Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue());
}
 
開發者ID:springuni,項目名稱:springuni-particles,代碼行數:11,代碼來源:Maps.java

示例12: toMap

import java.util.stream.Collectors; //導入方法依賴的package包/類
/**
 * Collect a stream of {@link Map.Entry} to a {@link Map} with the same key/value types
 * @param <K> the key type
 * @param <V> the value type
 * @return a map
 */
public static <K, V> Collector<Map.Entry<K, V>, ?, Map<K, V>> toMap() {
    return Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue);
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:10,代碼來源:CollectionUtils.java


注:本文中的java.util.stream.Collectors.toMap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。