java.util.HashMap.keySet()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(217)

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

HashMap.keySet介绍

[英]Returns a set view of the keys contained in this map.
[中]返回此映射中包含的键的集合视图。

代码示例

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

public Iterator<String> keyIterator() {
    if ( values == null ) {
      return emptyIter;
    }
    return values.keySet().iterator();
  }
}

代码示例来源:origin: apache/hive

/**
 * This method is used only for the analyze command to get the partition specs
 */
public TableSpec getTableSpec() {
 Iterator<String> tName = tableSpecs.keySet().iterator();
 return tableSpecs.get(tName.next());
}

代码示例来源:origin: apache/storm

@Override
  public void modifyOutputStream(JarOutputStream jarOut) throws IOException {
    for (String key : this.entries.keySet()) {
      jarOut.putNextEntry(new JarEntry(key));
      jarOut.write(this.entries.get(key).getBytes());
    }
  }
}

代码示例来源:origin: alibaba/jstorm

public void add(HashMap<String, ArrayList<TaskMessage>> workerTupleSetMap) {
  for (String key : workerTupleSetMap.keySet()) {
    ArrayList<ArrayList<TaskMessage>> bundle = bundles.get(key);
    if (null == bundle) {
      bundle = new ArrayList<>();
      bundles.put(key, bundle);
    }
    ArrayList tupleSet = workerTupleSetMap.get(key);
    if (null != tupleSet && tupleSet.size() > 0) {
      bundle.add(tupleSet);
    }
  }
}

代码示例来源:origin: apache/hive

@Override
public MapJoinKey getAnyKey() {
 return mHash.isEmpty() ? null : mHash.keySet().iterator().next();
}

代码示例来源:origin: Sable/soot

@Override
 protected void merge(HashMap<Value, Integer> in1, HashMap<Value, Integer> in2, HashMap<Value, Integer> out) {
  // Copy over in1. This will be the baseline
  out.putAll(in1);

  // Merge in in2. Make sure that we do not have ambiguous values.
  for (Value val : in2.keySet()) {
   Integer i1 = in1.get(val);
   Integer i2 = in2.get(val);
   if (i2.equals(i1)) {
    out.put(val, i2);
   } else {
    throw new RuntimeException("Merge of different IDs not supported");
   }
  }
 }
}

代码示例来源:origin: Atmosphere/atmosphere

public Enumeration<String> getInitParameterNames() {
    if (!done.getAndSet(true)) {
      Enumeration en = sc.getInitParameterNames();
      if (en != null) {
        while (en.hasMoreElements()) {
          String name = (String) en.nextElement();
          if (!initParams.containsKey(name)) {
            initParams.put(name, sc.getInitParameter(name));
          }
        }
      }
    }
    return Collections.enumeration(initParams.keySet());
  }
};

代码示例来源:origin: apache/drill

/**
 * This method is used only for the analyze command to get the partition specs
 */
public TableSpec getTableSpec() {
 Iterator<String> tName = tableSpecs.keySet().iterator();
 return tableSpecs.get(tName.next());
}

代码示例来源:origin: iSoron/uhabits

public void copyScoresFrom(@NonNull CacheData oldData)
{
  for (Long id : id_to_habit.keySet())
  {
    if (oldData.scores.containsKey(id))
      scores.put(id, oldData.scores.get(id));
    else scores.put(id, 0.0);
  }
}

代码示例来源:origin: apache/drill

@Override
public MapJoinKey getAnyKey() {
 return mHash.isEmpty() ? null : mHash.keySet().iterator().next();
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Convenience method for getting an iterator over the keys.
 * <p>
 * Write-only properties will not be returned in the iterator.
 *
 * @return an iterator over the keys
 */
public Iterator keyIterator() {
  return readMethods.keySet().iterator();
}

代码示例来源:origin: kaushikgopal/RxJava-Android-Samples

private List<String> mapAsList(HashMap<String, Long> map) {
 List<String> list = new ArrayList<>();
 for (String username : map.keySet()) {
  String rowLog = String.format("%s [%d]", username, contributionMap.get(username));
  list.add(rowLog);
 }
 return list;
}

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

public String[][] getHeaders(Object value, Operation operation) throws ServiceException {
  Response delegate = (Response) value;
  HashMap map = new HashMap();
  if (delegate.getContentDisposition() != null) {
    map.put("Content-Disposition", delegate.getContentDisposition());
  }
  HashMap m = delegate.getResponseHeaders();
  if (m != null && !m.isEmpty()) {
    map.putAll(m);
  }
  if (map == null || map.isEmpty()) return null;
  String[][] headers = new String[map.size()][2];
  List keys = new ArrayList(map.keySet());
  for (int i = 0; i < headers.length; i++) {
    headers[i][0] = (String) keys.get(i);
    headers[i][1] = (String) map.get(keys.get(i));
  }
  return headers;
}

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

public void foo() {

    m.put("a", "a");
    Set<Map.Entry<Integer, Integer>> es = new HashSet<Map.Entry<Integer, Integer>>();
    boolean b1 = m.entrySet().contains(1); // bad
    boolean b2 = m.keySet().contains(1); // ok
    boolean b3 = m.values().contains(1); // ok
    boolean b4 = m.entrySet().equals(es); // ok
    boolean b5 = m.entrySet().equals(is); // bad
    m.entrySet().contains(1); // bad
    boolean b6 = m.keySet().equals(is); // ok
    boolean b7 = m.values().equals(is); // ok
    System.out.printf("%b %b %b %b %b %b %b\n", b1, b2, b3, b4, b5, b6, b7);
  }
}

代码示例来源:origin: FudanNLP/fnlp

private void calcAV() {
  System.out.println("count: "+left.size());
  Iterator<String> it = left.keySet().iterator();		
  while(it.hasNext()){
    String key = it.next();
    Double l = Math.log(left.get(key).size());
    Double r = Math.log(right.get(key).size());
    av.put(key, (int)Math.min(l, r));
  }
  System.out.println("av count: "+av.size());
}

代码示例来源:origin: iSoron/uhabits

public void copyCheckmarksFrom(@NonNull CacheData oldData)
{
  int[] empty = new int[checkmarkCount];
  for (Long id : id_to_habit.keySet())
  {
    if (oldData.checkmarks.containsKey(id))
      checkmarks.put(id, oldData.checkmarks.get(id));
    else checkmarks.put(id, empty);
  }
}

代码示例来源:origin: apache/hive

private static void addBucketsToResultsCommon(
  HashMap<String, FileStatus> taskIDToFile, int numBuckets, List<Path> result) {
 String taskID1 = taskIDToFile.keySet().iterator().next();
 Path bucketPath = taskIDToFile.values().iterator().next().getPath();
 for (int j = 0; j < numBuckets; ++j) {
  addBucketFileIfMissing(result, taskIDToFile, taskID1, bucketPath, j);
 }
}

代码示例来源:origin: NanoHttpd/nanohttpd

@Override
public Iterator<String> iterator() {
  return this.cookies.keySet().iterator();
}

代码示例来源:origin: kaushikgopal/RxJava-Android-Samples

private List<String> getListStringFromMap() {
 List<String> list = new ArrayList<>();
 for (String username : _contributionMap.keySet()) {
  String rowLog = String.format("%s [%d]", username, _contributionMap.get(username));
  list.add(rowLog);
 }
 return list;
}

代码示例来源:origin: JetBrains/ideavim

@Nullable
private HashMap<Character, Mark> getAllFileMarks(@NotNull final Document doc) {
 VirtualFile vf = FileDocumentManager.getInstance().getFile(doc);
 if (vf == null) {
  return null;
 }
 HashMap<Character, Mark> res = new HashMap<>();
 FileMarks<Character, Mark> fileMarks = getFileMarks(doc);
 if (fileMarks != null) {
  res.putAll(fileMarks);
 }
 for (Character ch : globalMarks.keySet()) {
  Mark mark = globalMarks.get(ch);
  if (vf.getPath().equals(mark.getFilename())) {
   res.put(ch, mark);
  }
 }
 return res;
}

相关文章