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

How to use
keySet
method
in
java.util.Map

Best Java code snippets using java.util.Map.keySet (Showing top 20 results out of 163,953)

Refine searchRefine arrow

  • Map.get
  • Map.put
  • Set.iterator
  • Iterator.next
  • Iterator.hasNext
  • List.add
canonical example by Tabnine

private void mappingWordsLength(List<String> wordsList) {
 Map<Integer, Set<String>> mapping = new HashMap<>();
 for (String word : wordsList) {
  mapping.computeIfAbsent(word.length(), HashSet::new).add(word);
 }
 List<Integer> lengths = new LinkedList<>(mapping.keySet());
 Collections.sort(lengths);
 lengths.forEach(n -> System.out.println(mapping.get(n).size() + " words with " + n + " chars"));
}
origin: google/guava

 @Override
 public Iterator<C> apply(Map<C, V> input) {
  return input.keySet().iterator();
 }
}),
origin: spring-projects/spring-framework

/**
 * If the name is the expected name specified in the constructor, return the
 * object provided in the constructor. If the name is unexpected, a
 * respective NamingException gets thrown.
 */
@Override
public Object lookup(String name) throws NamingException {
  Object object = this.jndiObjects.get(name);
  if (object == null) {
    throw new NamingException("Unexpected JNDI name '" + name + "': expecting " + this.jndiObjects.keySet());
  }
  return object;
}
origin: square/okhttp

 @Override public void deleteContents(File directory) throws IOException {
  String prefix = directory.toString() + "/";
  for (Iterator<File> i = files.keySet().iterator(); i.hasNext(); ) {
   File file = i.next();
   if (file.toString().startsWith(prefix)) i.remove();
  }
 }
}
origin: apache/incubator-druid

 public static Map<String, Long> subtract(Map<String, Long> xs, Map<String, Long> ys)
 {
  assert xs.keySet().equals(ys.keySet());
  final Map<String, Long> zs = new HashMap<String, Long>();
  for (String k : xs.keySet()) {
   zs.put(k, xs.get(k) - ys.get(k));
  }
  return zs;
 }
}
origin: stanfordnlp/CoreNLP

 public List<String> getFilenames() {
  List<String> filenames = new ArrayList<>();
  for(String keyForFile : outFilenames.keySet())
   filenames.add(outFilenames.get(keyForFile));
  return filenames;
 }
}
origin: google/guava

 @Override
 public Iterable<Entry<E>> order(List<Entry<E>> insertionOrder) {
  // We mimic the order from gen.
  Map<E, Entry<E>> map = new LinkedHashMap<>();
  for (Entry<E> entry : insertionOrder) {
   map.put(entry.getElement(), entry);
  }
  Set<E> seen = new HashSet<>();
  List<Entry<E>> order = new ArrayList<>();
  for (E e : gen.order(new ArrayList<E>(map.keySet()))) {
   if (seen.add(e)) {
    order.add(map.get(e));
   }
  }
  return order;
 }
}
origin: square/okhttp

 @Override public void testRunFinished(Result result) throws Exception {
  Thread.setDefaultUncaughtExceptionHandler(oldDefaultUncaughtExceptionHandler);
  System.err.println("Uninstalled aggressive uncaught exception handler");

  synchronized (exceptions) {
   if (!exceptions.isEmpty()) {
    throw Throwables.rethrowAsException(exceptions.keySet().iterator().next());
   }
  }
 }
}
origin: apache/incubator-dubbo

@Override
public List<URL> lookup(URL url) {
  List<URL> urls = new ArrayList<>();
  Map<String, List<URL>> notifiedUrls = getNotified().get(url);
  if (notifiedUrls != null && notifiedUrls.size() > 0) {
    for (List<URL> values : notifiedUrls.values()) {
    for (URL u : getRegistered()) {
      if (UrlUtils.isMatch(url, u)) {
        urls.add(u);
    for (URL u : getSubscribed().keySet()) {
      if (UrlUtils.isMatch(url, u)) {
        urls.add(u);
origin: ctripcorp/apollo

private Set<String> stringPropertyNames(Properties properties) {
 //jdk9以下版本Properties#enumerateStringProperties方法存在性能问题,keys() + get(k) 重复迭代, jdk9之后改为entrySet遍历.
 Map<String, String> h = new HashMap<>();
 for (Map.Entry<Object, Object> e : properties.entrySet()) {
  Object k = e.getKey();
  Object v = e.getValue();
  if (k instanceof String && v instanceof String) {
   h.put((String) k, (String) v);
  }
 }
 return h.keySet();
}
origin: google/j2objc

public static void reverse(Map source, Map target) {
  for (Iterator it = source.keySet().iterator(); it.hasNext();) {
    Object key = it.next();
    target.put(source.get(key), key);
  }
}
origin: apache/kafka

private void createConnectionsMaxReauthMsMap(Map<String, ?> configs) {
  for (String mechanism : jaasContexts.keySet()) {
    String prefix = ListenerName.saslMechanismPrefix(mechanism);
    Long connectionsMaxReauthMs = (Long) configs.get(prefix + BrokerSecurityConfigs.CONNECTIONS_MAX_REAUTH_MS);
    if (connectionsMaxReauthMs == null)
      connectionsMaxReauthMs = (Long) configs.get(BrokerSecurityConfigs.CONNECTIONS_MAX_REAUTH_MS);
    if (connectionsMaxReauthMs != null)
      connectionsMaxReauthMsByMechanism.put(mechanism, connectionsMaxReauthMs);
  }
}
origin: spring-projects/spring-framework

/**
 * Return the {@link Method} mapped to the given exception type, or {@code null} if none.
 */
@Nullable
private Method getMappedMethod(Class<? extends Throwable> exceptionType) {
  List<Class<? extends Throwable>> matches = new ArrayList<>();
  for (Class<? extends Throwable> mappedException : this.mappedMethods.keySet()) {
    if (mappedException.isAssignableFrom(exceptionType)) {
      matches.add(mappedException);
    }
  }
  if (!matches.isEmpty()) {
    matches.sort(new ExceptionDepthComparator(exceptionType));
    return this.mappedMethods.get(matches.get(0));
  }
  else {
    return null;
  }
}
origin: Alluxio/alluxio

@Override
public Map<String, List<String>> getDirectoryPathsOnTiers() {
 Map<String, List<String>> pathsOnTiers = new HashMap<>();
 for (Pair<String, String> tierPath : mCapacityBytesOnDirs.keySet()) {
  String tier = tierPath.getFirst();
  if (pathsOnTiers.get(tier) == null) {
   pathsOnTiers.put(tier, new ArrayList<String>());
  }
  pathsOnTiers.get(tier).add(tierPath.getSecond());
 }
 return pathsOnTiers;
}
origin: google/guava

static <K extends Enum<K>> Class<K> inferKeyType(Map<K, ?> map) {
 if (map instanceof EnumBiMap) {
  return ((EnumBiMap<K, ?>) map).keyType();
 }
 if (map instanceof EnumHashBiMap) {
  return ((EnumHashBiMap<K, ?>) map).keyType();
 }
 checkArgument(!map.isEmpty());
 return map.keySet().iterator().next().getDeclaringClass();
}
origin: stackoverflow.com

 Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Integer key : map.keySet()) {
  Integer value = map.get(key);
  System.out.println("Key = " + key + ", Value = " + value);
}
origin: apache/incubator-dubbo

@Override
public List<URL> lookup(URL url) {
  List<URL> urls = new ArrayList<>();
  Map<String, List<URL>> notifiedUrls = getNotified().get(url);
  if (notifiedUrls != null && notifiedUrls.size() > 0) {
    for (List<URL> values : notifiedUrls.values()) {
    for (URL u : getRegistered()) {
      if (UrlUtils.isMatch(url, u)) {
        urls.add(u);
    for (URL u : getSubscribed().keySet()) {
      if (UrlUtils.isMatch(url, u)) {
        urls.add(u);
origin: spring-projects/spring-framework

@Override
public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType)
    throws BeansException {
  Map<String, Object> results = new LinkedHashMap<>();
  for (String beanName : this.beans.keySet()) {
    if (findAnnotationOnBean(beanName, annotationType) != null) {
      results.put(beanName, getBean(beanName));
    }
  }
  return results;
}
origin: spring-projects/spring-framework

/**
 * Return all declared prefixes.
 */
public Iterator<String> getBoundPrefixes() {
  return this.prefixToNamespaceUri.keySet().iterator();
}
origin: stanfordnlp/CoreNLP

private void filterFeatures(Set<String> keep) {
 Iterator<String> featureIt = featureWeights.keySet().iterator();
 while (featureIt.hasNext()) {
  if (!keep.contains(featureIt.next())) {
   featureIt.remove();
  }
 }
}
java.utilMapkeySet

Javadoc

Returns a set of the keys contained in this Map. The Set is backed by this Map so changes to one are reflected by the other. The Set does not support adding.

Popular methods of Map

  • put
    Maps the specified key to the specified value.
  • get
  • entrySet
    Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes t
  • containsKey
    Returns whether this Map contains the specified key.
  • 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
  • Best IntelliJ plugins
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