java.util.AbstractMap.entrySet()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中java.util.AbstractMap.entrySet()方法的一些代码示例,展示了AbstractMap.entrySet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractMap.entrySet()方法的具体详情如下:
包路径:java.util.AbstractMap
类名称:AbstractMap
方法名:entrySet

AbstractMap.entrySet介绍

[英]Returns a set view of the mappings contained in this map. Each element in this set is a Map.Entry. 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, the results of the iteration are undefined.) The set supports element removal, which removes the corresponding entry from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
[中]返回此映射中包含的映射的集合视图。此集合中的每个元素都是一个映射。进入集合由映射支持,因此对映射的更改将反映在集合中,反之亦然。(如果在对集合进行迭代时修改贴图,则迭代的结果未定义。)该集合支持元素删除,即通过迭代器从映射中删除相应的条目。移除,设置。移除、移除所有、保留和清除操作。它不支持添加或添加所有操作。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * {@inheritDoc}
 *
 * <p>This implementation returns its entry set's size.
 */
public int size() {
  return entrySet().size();
}

代码示例来源:origin: robovm/robovm

/**
 * {@inheritDoc}
 *
 * <p>This implementation calls {@code entrySet().clear()}.
 */
public void clear() {
  entrySet().clear();
}

代码示例来源:origin: robovm/robovm

/**
 * {@inheritDoc}
 *
 * <p>This implementation iterates its entry set, summing the hashcodes of
 * its entries.
 */
@Override public int hashCode() {
  int result = 0;
  Iterator<Map.Entry<K, V>> it = entrySet().iterator();
  while (it.hasNext()) {
    result += it.next().hashCode();
  }
  return result;
}

代码示例来源:origin: robovm/robovm

/**
 * {@inheritDoc}
 *
 * <p>This implementation iterates its key set, looking for a key that
 * {@code key} equals.
 */
public boolean containsKey(Object key) {
  Iterator<Map.Entry<K, V>> it = entrySet().iterator();
  if (key != null) {
    while (it.hasNext()) {
      if (key.equals(it.next().getKey())) {
        return true;
      }
    }
  } else {
    while (it.hasNext()) {
      if (it.next().getKey() == null) {
        return true;
      }
    }
  }
  return false;
}

代码示例来源:origin: robovm/robovm

/**
 * {@inheritDoc}
 *
 * <p>This implementation iterates its entry set, looking for an entry with
 * a value that {@code value} equals.
 */
public boolean containsValue(Object value) {
  Iterator<Map.Entry<K, V>> it = entrySet().iterator();
  if (value != null) {
    while (it.hasNext()) {
      if (value.equals(it.next().getValue())) {
        return true;
      }
    }
  } else {
    while (it.hasNext()) {
      if (it.next().getValue() == null) {
        return true;
      }
    }
  }
  return false;
}

代码示例来源:origin: robovm/robovm

/**
 * {@inheritDoc}
 *
 * <p>This implementation iterates its entry set, looking for an entry with
 * a key that {@code key} equals.
 */
public V get(Object key) {
  Iterator<Map.Entry<K, V>> it = entrySet().iterator();
  if (key != null) {
    while (it.hasNext()) {
      Map.Entry<K, V> entry = it.next();
      if (key.equals(entry.getKey())) {
        return entry.getValue();
      }
    }
  } else {
    while (it.hasNext()) {
      Map.Entry<K, V> entry = it.next();
      if (entry.getKey() == null) {
        return entry.getValue();
      }
    }
  }
  return null;
}

代码示例来源:origin: robovm/robovm

/**
 * {@inheritDoc}
 *
 * <p>This implementation iterates its entry set, removing the entry with
 * a key that {@code key} equals.
 */
public V remove(Object key) {
  Iterator<Map.Entry<K, V>> it = entrySet().iterator();
  if (key != null) {
    while (it.hasNext()) {
      Map.Entry<K, V> entry = it.next();
      if (key.equals(entry.getKey())) {
        it.remove();
        return entry.getValue();
      }
    }
  } else {
    while (it.hasNext()) {
      Map.Entry<K, V> entry = it.next();
      if (entry.getKey() == null) {
        it.remove();
        return entry.getValue();
      }
    }
  }
  return null;
}

代码示例来源:origin: robovm/robovm

for (Entry<K, V> entry : entrySet()) {
  K key = entry.getKey();
  V mine = entry.getValue();

代码示例来源:origin: robovm/robovm

Iterator<Map.Entry<K, V>> it = entrySet().iterator();
while (it.hasNext()) {
  Map.Entry<K, V> entry = it.next();

代码示例来源:origin: stackoverflow.com

for (Object obj : map.entrySet()) {
  Map.Entry entry = (Map.Entry) obj;
  writer.startNode(entry.getKey().toString());

代码示例来源:origin: stackoverflow.com

public class MapEntryConverter implements Converter{
public boolean canConvert(Class clazz) {
  return AbstractMap.class.isAssignableFrom(clazz);
}

public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
  AbstractMap<String,String> map = (AbstractMap<String,String>) value;
  for (Entry<String,String> entry : map.entrySet()) {
    writer.startNode(entry.getKey().toString());
    writer.setValue(entry.getValue().toString());
    writer.endNode();
  }
}

public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
  Map<String, String> map = new HashMap<String, String>();

  while(reader.hasMoreChildren()) {
    reader.moveDown();
    map.put(reader.getNodeName(), reader.getValue());
    reader.moveUp();
  }
  return map;
}

代码示例来源:origin: MobiVM/robovm

/**
 * {@inheritDoc}
 *
 * <p>This implementation returns its entry set's size.
 */
public int size() {
  return entrySet().size();
}

代码示例来源:origin: ibinti/bugvm

/**
 * {@inheritDoc}
 *
 * <p>This implementation calls {@code entrySet().clear()}.
 */
public void clear() {
  entrySet().clear();
}

代码示例来源:origin: ibinti/bugvm

/**
 * {@inheritDoc}
 *
 * <p>This implementation returns its entry set's size.
 */
public int size() {
  return entrySet().size();
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * {@inheritDoc}
 *
 * <p>This implementation calls {@code entrySet().clear()}.
 */
public void clear() {
  entrySet().clear();
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * {@inheritDoc}
 *
 * <p>This implementation returns its entry set's size.
 */
public int size() {
  return entrySet().size();
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * {@inheritDoc}
 *
 * <p>This implementation calls {@code entrySet().clear()}.
 */
public void clear() {
  entrySet().clear();
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * {@inheritDoc}
 *
 * <p>This implementation returns its entry set's size.
 */
public int size() {
  return entrySet().size();
}

代码示例来源:origin: com.jtransc/jtransc-rt

/**
 * {@inheritDoc}
 *
 * <p>This implementation calls {@code entrySet().clear()}.
 */
public void clear() {
  entrySet().clear();
}

代码示例来源:origin: MobiVM/robovm

/**
 * {@inheritDoc}
 *
 * <p>This implementation calls {@code entrySet().clear()}.
 */
public void clear() {
  entrySet().clear();
}

相关文章