Tabnine Logo
Map.entrySet
Code IndexAdd Tabnine to your IDE (free)

How to use
entrySet
method
in
java.util.Map

Best Java code snippets using java.util.Map.entrySet (Showing top 20 results out of 208,431)

Refine searchRefine arrow

  • Map.Entry.getKey
  • Map.Entry.getValue
  • Map.put
  • Map.get
  • Map.size
  • Iterator.next
origin: stackoverflow.com

 public static void printMap(Map mp) {
  Iterator it = mp.entrySet().iterator();
  while (it.hasNext()) {
    Map.Entry pair = (Map.Entry)it.next();
    System.out.println(pair.getKey() + " = " + pair.getValue());
    it.remove(); // avoids a ConcurrentModificationException
  }
}
origin: google/guava

/** An implementation of {@link Map#putAll}. */
static <K, V> void putAllImpl(Map<K, V> self, Map<? extends K, ? extends V> map) {
 for (Entry<? extends K, ? extends V> entry : map.entrySet()) {
  self.put(entry.getKey(), entry.getValue());
 }
}
origin: google/guava

/**
 * Stores the contents of a map in an output stream, as part of serialization. It does not support
 * concurrent maps whose content may change while the method is running.
 *
 * <p>The serialized output consists of the number of entries, first key, first value, second key,
 * second value, and so on.
 */
static <K, V> void writeMap(Map<K, V> map, ObjectOutputStream stream) throws IOException {
 stream.writeInt(map.size());
 for (Map.Entry<K, V> entry : map.entrySet()) {
  stream.writeObject(entry.getKey());
  stream.writeObject(entry.getValue());
 }
}
origin: apache/kafka

private void innerUpdateEndOffsets(final Map<TopicPartition, Long> newOffsets,
                  final boolean replace) {
  for (final Map.Entry<TopicPartition, Long> entry : newOffsets.entrySet()) {
    List<Long> offsets = endOffsets.get(entry.getKey());
    if (replace || offsets == null) {
      offsets = new ArrayList<>();
    }
    offsets.add(entry.getValue());
    endOffsets.put(entry.getKey(), offsets);
  }
}
origin: prestodb/presto

public Map<String, Double> getOperatorHashCollisionsAverages()
{
  return operatorHashCollisionsStats.entrySet().stream()
      .collect(toMap(
          Map.Entry::getKey,
          entry -> entry.getValue().getWeightedHashCollisions() / operatorInputStats.get(entry.getKey()).getInputPositions()));
}
origin: bumptech/glide

private Map<String, List<LazyHeaderFactory>> copyHeaders() {
 Map<String, List<LazyHeaderFactory>> result = new HashMap<>(headers.size());
 for (Map.Entry<String, List<LazyHeaderFactory>> entry : headers.entrySet()) {
  @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
  List<LazyHeaderFactory> valueCopy = new ArrayList<>(entry.getValue());
  result.put(entry.getKey(), valueCopy);
 }
 return result;
}
origin: spring-projects/spring-framework

/**
 * Match the provided column names and values with the list of columns used.
 * @param inParameters the parameter names and values
 */
public List<Object> matchInParameterValuesWithInsertColumns(Map<String, ?> inParameters) {
  List<Object> values = new ArrayList<>(inParameters.size());
  for (String column : this.tableColumns) {
    Object value = inParameters.get(column);
    if (value == null) {
      value = inParameters.get(column.toLowerCase());
      if (value == null) {
        for (Map.Entry<String, ?> entry : inParameters.entrySet()) {
          if (column.equalsIgnoreCase(entry.getKey())) {
            value = entry.getValue();
            break;
          }
        }
      }
    }
    values.add(value);
  }
  return values;
}
origin: google/guava

@CanIgnoreReturnValue
private Map<R, V> removeColumn(Object column) {
 Map<R, V> output = new LinkedHashMap<>();
 Iterator<Entry<R, Map<C, V>>> iterator = backingMap.entrySet().iterator();
 while (iterator.hasNext()) {
  Entry<R, Map<C, V>> entry = iterator.next();
  V value = entry.getValue().remove(column);
  if (value != null) {
   output.put(entry.getKey(), value);
   if (entry.getValue().isEmpty()) {
    iterator.remove();
   }
  }
 }
 return output;
}
origin: google/guava

public void testEntrySetSetValueSameValue() {
 // TODO: Investigate the extent to which, in practice, maps that support
 // put() also support Entry.setValue().
 if (!supportsPut) {
  return;
 }
 final Map<K, V> map;
 try {
  map = makePopulatedMap();
 } catch (UnsupportedOperationException e) {
  return;
 }
 Set<Entry<K, V>> entrySet = map.entrySet();
 Entry<K, V> entry = entrySet.iterator().next();
 final V oldValue = entry.getValue();
 final V returnedValue = entry.setValue(oldValue);
 assertEquals(oldValue, returnedValue);
 assertTrue(entrySet.contains(mapEntry(entry.getKey(), oldValue)));
 assertEquals(oldValue, map.get(entry.getKey()));
 assertInvariants(map);
}
origin: apache/flink

@Test
public void testGetEnvironmentVariables() {
  Configuration testConf = new Configuration();
  testConf.setString("yarn.application-master.env.LD_LIBRARY_PATH", "/usr/lib/native");
  Map<String, String> res = Utils.getEnvironmentVariables("yarn.application-master.env.", testConf);
  Assert.assertEquals(1, res.size());
  Map.Entry<String, String> entry = res.entrySet().iterator().next();
  Assert.assertEquals("LD_LIBRARY_PATH", entry.getKey());
  Assert.assertEquals("/usr/lib/native", entry.getValue());
}
origin: google/guava

@Override
public void putAll(Map<? extends K, ? extends V> m) {
 for (Entry<? extends K, ? extends V> e : m.entrySet()) {
  put(e.getKey(), e.getValue());
 }
}
origin: google/guava

static <T extends StandardTable<Object, Object, Object>> T populate(
  SerializationStreamReader reader, T table) throws SerializationException {
 Map<?, ?> hashMap = (Map<?, ?>) reader.readObject();
 for (Entry<?, ?> row : hashMap.entrySet()) {
  table.row(row.getKey()).putAll((Map<?, ?>) row.getValue());
 }
 return table;
}
origin: apache/incubator-dubbo

/**
 * put all.
 *
 * @param map map.
 */
public void putAll(Map<String, Object> map) {
  for (Map.Entry<String, Object> entry : map.entrySet()) {
    mMap.put(entry.getKey(), entry.getValue());
  }
}
origin: prestodb/presto

@Override
public BenchmarkResultHook addResults(Map<String, Long> results)
{
  requireNonNull(results, "results is null");
  for (Entry<String, Long> entry : results.entrySet()) {
    Long currentSum = resultsSum.get(entry.getKey());
    if (currentSum == null) {
      currentSum = 0L;
    }
    resultsSum.put(entry.getKey(), currentSum + entry.getValue());
  }
  resultsCount++;
  return this;
}
origin: prestodb/presto

public Map<String, Double> getOperatorExpectedCollisionsAverages()
{
  return operatorHashCollisionsStats.entrySet().stream()
      .collect(toMap(
          Map.Entry::getKey,
          entry -> entry.getValue().getWeightedExpectedHashCollisions() / operatorInputStats.get(entry.getKey()).getInputPositions()));
}
origin: stackoverflow.com

 Map map = new HashMap();
Iterator entries = map.entrySet().iterator();
while (entries.hasNext()) {
  Map.Entry entry = (Map.Entry) entries.next();
  Integer key = (Integer)entry.getKey();
  Integer value = (Integer)entry.getValue();
  System.out.println("Key = " + key + ", Value = " + value);
}
origin: spring-projects/spring-framework

private Map<String, Class<?>> toClassMap(Map<String, ?> map) throws ClassNotFoundException {
  Map<String, Class<?>> result = new LinkedHashMap<>(map.size());
  for (Map.Entry<String, ?> entry : map.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    Class<?> type;
    if (value instanceof Class) {
      type = (Class<?>) value;
    }
    else if (value instanceof String) {
      String className = (String) value;
      type = ClassUtils.forName(className, this.beanClassLoader);
    }
    else {
      throw new IllegalArgumentException("Unknown value [" + value + "] - expected String or Class");
    }
    result.put(key, type);
  }
  return result;
}
origin: jenkinsci/jenkins

private PackedMap(Map<? extends K,? extends V> src) {
  kvpairs = new Object[src.size()*2];
  int i=0;
  for (Entry<? extends K, ? extends V> e : src.entrySet()) {
    kvpairs[i++] = e.getKey();
    kvpairs[i++] = e.getValue();
  }
}
origin: apache/incubator-dubbo

public static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2) {
  if (map1 == null && map2 == null) {
    return true;
  }
  if (map1 == null || map2 == null) {
    return false;
  }
  if (map1.size() != map2.size()) {
    return false;
  }
  for (Map.Entry<?, ?> entry : map1.entrySet()) {
    Object key = entry.getKey();
    Object value1 = entry.getValue();
    Object value2 = map2.get(key);
    if (!objectEquals(value1, value2)) {
      return false;
    }
  }
  return true;
}
origin: google/guava

public void testFilteredValuesIllegalSetValue() {
 Map<String, Integer> unfiltered = createUnfiltered();
 Map<String, Integer> filtered = Maps.filterValues(unfiltered, EVEN);
 filtered.put("a", 2);
 filtered.put("b", 4);
 assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered);
 Entry<String, Integer> entry = filtered.entrySet().iterator().next();
 try {
  entry.setValue(5);
  fail();
 } catch (IllegalArgumentException expected) {
 }
 assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered);
}
java.utilMapentrySet

Javadoc

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Popular methods of Map

  • put
    Maps the specified key to the specified value.
  • get
  • containsKey
    Returns whether this Map contains the specified key.
  • keySet
    Returns a set of the keys contained in this Map. The Set is backed by this Map so changes to one are
  • values
    Returns a Collection view of the values contained in this map. The collection is backed by the map,
  • remove
  • size
    Returns the number of mappings in this Map.
  • isEmpty
    Returns true if this map contains no key-value mappings.
  • clear
    Removes all elements from this Map, leaving it empty.
  • putAll
    Copies all of the mappings from the specified map to this map (optional operation). The effect of th
  • forEach
  • equals
    Compares the argument to the receiver, and returns true if the specified object is a Map and both Ma
  • forEach,
  • equals,
  • computeIfAbsent,
  • hashCode,
  • getOrDefault,
  • containsValue,
  • putIfAbsent,
  • compute,
  • merge

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • getResourceAsStream (ClassLoader)
  • findViewById (Activity)
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now