本文整理了Java中java.util.HashMap.put()
方法的一些代码示例,展示了HashMap.put()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashMap.put()
方法的具体详情如下:
包路径:java.util.HashMap
类名称:HashMap
方法名:put
[英]Maps the specified key to the specified value.
[中]将指定的键映射到指定的值。
代码示例来源:origin: google/guava
private static <K, V> HashMap<K, V> newHashMap(
Collection<? extends Entry<? extends K, ? extends V>> entries) {
HashMap<K, V> map = new HashMap<>();
for (Entry<? extends K, ? extends V> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
return map;
}
}
代码示例来源:origin: libgdx/libgdx
public final int[] getIntArray(int argLength) {
if (!aints.containsKey(argLength)) {
aints.put(argLength, new int[argLength]);
}
assert (aints.get(argLength).length == argLength) : "Array not built with correct length";
return aints.get(argLength);
}
代码示例来源:origin: Tencent/tinker
void putSanitizeName(RType rType, String sanitizeName, String rawName) {
HashMap<String, String> sanitizeNameMap;
if (!sanitizeTypeMap.containsKey(rType)) {
sanitizeNameMap = new HashMap<>();
sanitizeTypeMap.put(rType, sanitizeNameMap);
} else {
sanitizeNameMap = sanitizeTypeMap.get(rType);
}
if (!sanitizeNameMap.containsKey(sanitizeName)) {
sanitizeNameMap.put(sanitizeName, rawName);
}
}
代码示例来源:origin: alibaba/jstorm
public static <V> HashMap<V, Integer> multi_set(List<V> list) {
HashMap<V, Integer> rtn = new HashMap<>();
for (V v : list) {
int cnt = 1;
if (rtn.containsKey(v)) {
cnt += rtn.get(v);
}
rtn.put(v, cnt);
}
return rtn;
}
代码示例来源:origin: apache/hive
private static Map<String, Object> createVersions() {
ArrayList<String> versions = new ArrayList<String>();
versions.add(VERSION);
HashMap<String, Object> res = new HashMap<String, Object>();
res.put("supportedVersions", versions);
res.put("version", VERSION);
return Collections.unmodifiableMap(res);
}
代码示例来源:origin: apache/storm
public static void registerMetricsConsumer(Map<String, Object> conf, Class klass, Object argument, long parallelismHint) {
HashMap<String, Object> m = new HashMap<>();
m.put("class", klass.getCanonicalName());
m.put("parallelism.hint", parallelismHint);
m.put("argument", argument);
List l = (List) conf.get(TOPOLOGY_METRICS_CONSUMER_REGISTER);
if (l == null) {
l = new ArrayList();
}
l.add(m);
conf.put(TOPOLOGY_METRICS_CONSUMER_REGISTER, l);
}
代码示例来源:origin: stackoverflow.com
HashMap<Integer, String> map = new HashMap<Integer, String>();
map.put (1, "Mark");
map.put (2, "Tarryn");
List<String> list = new ArrayList<String>(map.values());
for (String s : list) {
System.out.println(s);
}
代码示例来源:origin: apache/rocketmq
private HashMap<String/* brokerName */, Set<MessageQueue>> buildProcessQueueTableByBrokerName() {
HashMap<String, Set<MessageQueue>> result = new HashMap<String, Set<MessageQueue>>();
for (MessageQueue mq : this.processQueueTable.keySet()) {
Set<MessageQueue> mqs = result.get(mq.getBrokerName());
if (null == mqs) {
mqs = new HashSet<MessageQueue>();
result.put(mq.getBrokerName(), mqs);
}
mqs.add(mq);
}
return result;
}
代码示例来源:origin: stackoverflow.com
HashMap<String, Double> map = new HashMap<String, Double>();
ValueComparator bvc = new ValueComparator(map);
TreeMap<String, Double> sorted_map = new TreeMap<String, Double>(bvc);
map.put("A", 99.5);
map.put("B", 67.4);
map.put("C", 67.4);
map.put("D", 67.3);
System.out.println("unsorted map: " + map);
sorted_map.putAll(map);
System.out.println("results: " + sorted_map);
代码示例来源:origin: FudanNLP/fnlp
private int add(Word w) {
Integer id = index.get(w.word);
if(id==null){
id = words.size();
words.add(w);
index.put(w.word, id);
}
return id;
}
代码示例来源:origin: apache/kafka
@Override
public Map<Errors, Integer> errorCounts() {
HashMap<Errors, Integer> counts = new HashMap<>();
for (ReplicaElectionResult result : data.replicaElectionResults()) {
for (PartitionResult partitionResult : result.partitionResult()) {
Errors error = Errors.forCode(partitionResult.errorCode());
counts.put(error, counts.getOrDefault(error, 0) + 1);
}
}
return counts;
}
代码示例来源:origin: libgdx/libgdx
public void setEnabled (ParticleEmitter emitter, boolean enabled) {
ParticleData data = particleData.get(emitter);
if (data == null) particleData.put(emitter, data = new ParticleData());
data.enabled = enabled;
emitter.reset();
}
代码示例来源:origin: stackoverflow.com
List<Integer> numbers = new ArrayList<Integer>(){{ add(1); add(2); }};
Map<String,String> codes = new HashMap<String,String>(){{
put("1","one");
put("2","two");
}};
代码示例来源:origin: apache/rocketmq
public void buildRunningStats(HashMap<String, String> stats) {
Iterator<Entry<Integer, Long>> it = this.offsetTable.entrySet().iterator();
while (it.hasNext()) {
Entry<Integer, Long> next = it.next();
int queueId = delayLevel2QueueId(next.getKey());
long delayOffset = next.getValue();
long maxOffset = this.defaultMessageStore.getMaxOffsetInQueue(SCHEDULE_TOPIC, queueId);
String value = String.format("%d,%d", delayOffset, maxOffset);
String key = String.format("%s_%d", RunningStats.scheduleMessageOffset.name(), next.getKey());
stats.put(key, value);
}
}
代码示例来源:origin: alibaba/jstorm
public static <V> HashMap<V, Integer> multi_set(List<V> list) {
HashMap<V, Integer> rtn = new HashMap<V, Integer>();
for (V v : list) {
int cnt = 1;
if (rtn.containsKey(v)) {
cnt += rtn.get(v);
}
rtn.put(v, cnt);
}
return rtn;
}
代码示例来源:origin: apache/hive
private static Map<String, Object> createFormats() {
ArrayList<String> formats = new ArrayList<String>();
formats.add(MediaType.APPLICATION_JSON);
HashMap<String, Object> res = new HashMap<String, Object>();
res.put("responseTypes", formats);
return Collections.unmodifiableMap(res);
}
代码示例来源:origin: gocd/gocd
private static Map<String, Object> sanitize(Map<String, Object> flatMap) {
HashMap<String, Object> santizedMap = new HashMap<>();
for (Map.Entry<String, Object> entry : flatMap.entrySet()) {
santizedMap.put(entry.getKey().toLowerCase(), entry.getValue());
}
return santizedMap;
}
代码示例来源:origin: alibaba/jstorm
public static void registerMetricsConsumer(Map conf, Class klass, Object argument, long parallelismHint) {
HashMap m = new HashMap();
m.put("class", klass.getCanonicalName());
m.put("parallelism.hint", parallelismHint);
m.put("argument", argument);
List l = (List) conf.get(TOPOLOGY_METRICS_CONSUMER_REGISTER);
if (l == null) {
l = new ArrayList();
}
l.add(m);
conf.put(TOPOLOGY_METRICS_CONSUMER_REGISTER, l);
}
代码示例来源:origin: apache/incubator-dubbo
/**
* <code><pre>
* type ::= string
* ::= int
* </code></pre>
*/
private void writeType(String type)
throws IOException {
flushIfFull();
int len = type.length();
if (len == 0) {
throw new IllegalArgumentException("empty type is not allowed");
}
if (_typeRefs == null)
_typeRefs = new HashMap();
Integer typeRefV = (Integer) _typeRefs.get(type);
if (typeRefV != null) {
int typeRef = typeRefV.intValue();
writeInt(typeRef);
} else {
_typeRefs.put(type, Integer.valueOf(_typeRefs.size()));
writeString(type);
}
}
代码示例来源:origin: libgdx/libgdx
public final float[] getFloatArray(int argLength) {
if (!afloats.containsKey(argLength)) {
afloats.put(argLength, new float[argLength]);
}
assert (afloats.get(argLength).length == argLength) : "Array not built with correct length";
return afloats.get(argLength);
}
内容来源于网络,如有侵权,请联系作者删除!