hashmap

2019最新整理JAVA面试题附答案

笑着哭i 提交于 2019-12-28 15:37:08
本人免费整理了Java高级资料,涵盖了Java、Redis、MongoDB、MySQL、Zookeeper、Spring Cloud、Dubbo高并发分布式等教程,一共30G,需要自己领取。 传送门: https://mp.weixin.qq.com/s/igMojff-bbmQ6irCGO3mqA 包含的模块: 本文分为十九个模块,分别是:Java 基础、容器、多线程、反射、对象拷贝、Java Web 、异常、网络、设计模式、Spring/Spring MVC、Spring Boot/Spring Cloud、Hibernate、MyBatis、RabbitMQ、Kafka、Zookeeper、MySQL、Redis、JVM 如下图所示: 共包含 208 道面试题,本文的宗旨是为读者朋友们整理一份详实而又权威的面试清单,下面一起进入主题吧。 ==================================================== 一. Java 基础模块 1.JDK 和 JRE 有什么区别? JDK:Java Development Kit 的简称,Java 开发工具包,提供了 Java 的开发环境和运行环境。 JRE:Java Runtime Environment 的简称,Java 运行环境,为 Java 的运行提供了所需环境。 具体来说 JDK 其实包含了

Displaying Hashmap keys and values in a primefaces DataTable

℡╲_俬逩灬. 提交于 2019-12-28 11:53:17
问题 I'm trying to display a Hashmap in a DataTable, here's what i'm trying to do : I'll have a select menu of some products, and an input text for quantity, an "ajaxified" add button that adds the product and its quantity to the map, and a submit button that displays a summary dialog containing a DataTable with two columns : Product Name and Quantitiy. my Hashmap is Map<Product,Integer> myMap = new HashMap<Product,Integer>(); for the ajaxified button and all those first steps, they're working for

ConcurrentModificationException when using stream with Maps key set

送分小仙女□ 提交于 2019-12-28 06:33:05
问题 I want to remove all items from someMap which keys are not present in someList . Take a look into my code: someMap.keySet().stream().filter(v -> !someList.contains(v)).forEach(someMap::remove); I receive java.util.ConcurrentModificationException . Why? Stream is not parallel. What is the most elegant way to do this? 回答1: @Eran already explained how to solve this problem better. I will explain why ConcurrentModificationException occurs. The ConcurrentModificationException occurs because you

two unequal objects with same hashcode

☆樱花仙子☆ 提交于 2019-12-28 05:23:04
问题 Hashcode() and equals() concept is 1) If two Objects are equal according to equal(), then calling the hashcode method on each of those two objects should produce same hashcode. and other one is 2) It is not required that if two objects are unequal according to the equal(), then calling the hashcode method on each of the two objects must produce distinct values. I tried and understood first one and this is the code for first point. public class Test { public static void main(String[] args) {

Internal implementation of java.util.HashMap and HashSet

雨燕双飞 提交于 2019-12-28 05:10:42
问题 I have been trying to understand the internal implementation of java.util.HashMap and java.util.HashSet . Following are the doubts popping in my mind for a while: Whats is the importance of the @Override public int hashcode() in a HashMap/HashSet? Where is this hash code used internally? I have generally seen the key of the HashMap be a String like myMap<String,Object> . Can I map the values against someObject (instead of String) like myMap<someObject, Object> ? What all contracts do I need

Is there Java HashMap equivalent in PHP?

主宰稳场 提交于 2019-12-28 04:54:06
问题 I need PHP object similar to HashMap in Java, but I didn't find when I googled, so if someone knows how I can mimic HashMaps in PHP, help would be appreciated. 回答1: Arrays in PHP can have Key Value structure. 回答2: Depending on what you want you might be interested in the SPL Object Storage class. http://php.net/manual/en/class.splobjectstorage.php It lets you use objects as keys, has an interface to count, get the hash and other goodies. $s = new SplObjectStorage; $o1 = new stdClass; $o2 =

How to use Map element as text of a JComboBox

吃可爱长大的小学妹 提交于 2019-12-28 04:15:08
问题 I am populating a JComboBox (using addItem() ) with all the elements of a collection. Each element in the collection is a HashMap (so its a ComboBox of Hashmaps..). My question is - Given that I need each item to be a HashMap how do I set the text to apear in the combobox on the GUI? It needs to be the value of a certain key in the map. Normally if I am populating a combobox with my own type, I would just overide the toString() method...but I am not sure how to acheive this since I am using a

HashMap和HashTable

倾然丶 夕夏残阳落幕 提交于 2019-12-28 03:07:00
JAVA的基础知识:数据结构(Map,List,Set等),设计模式,算法,线程相关,IO/NIO,序列化等等 其次是高级特征:反射机制,并发与锁,JVM(GC策略,类加载机制,内存模型)等等 举个例子 就比如问你:HashMap 是不是有序的? 你回答不是有序的。那面试官就会可能继续问你,有没有有序的Map实现类呢? 你如果这个时候说不知道的话,那这块问题就到此结束了。如果你说有TreeMap和LinkedHashMap。 那么面试官接下来就可能会问你,TreeMap和LinkedHashMap是如何保证它的顺序的? 如果你回答不上来,那么到此为止。 如果你说TreeMap是通过实现SortMap接口,能够把它保存的键值对根据key排序,基于红黑树,从而保证TreeMap中所有键值对处于有序状态。 LinkedHashMap则是通过插入排序(就是你put的时候的顺序是什么,取出来的时候就是什么样子)和访问排序(改变排序把访问过的放到底部)让键值有序。 1、为什么用HashMap? HashMap是一个散列桶(数组和链表),它存储的内容是键值对(key-value)映射 HashMap采用了数组和链表的数据结构,能在查询和修改方便继承了数组的线性查找和链表的寻址修改 HashMap是非synchronized,所以HashMap很快 HashMap可以接受null键和值

移动开发:APP定位过于频繁,我用这种方式“揪出元凶”!

℡╲_俬逩灬. 提交于 2019-12-28 00:56:08
背景 定位现在是很多APP最基本也不可或缺的能力之一,尤其是对打车、外卖之类的应用来说。但对定位的调用可不能没有节制,稍有不慎可能导致设备耗电过快,最终导致用户卸载应用。 笔者所在项目是一个在后台运行的APP,且需要时不时在后台获取一下当前位置,再加上项目里会引入很多合作第三方的库,这些库内部同样也会有调用定位的行为,因此经常会收到测试的反馈说我们的应用由于定位过于频繁导致耗电过快。 排查这个问题的时候,笔者首先排除了我们业务逻辑的问题,因为项目中的各个功能模块在定位时调用的是统一封装后的定位模块接口,该模块中由对相应的接口做了一些调用频率的统计和监控并打印了相关的log语句, 而问题log中跟定位相关的log语句打印频率跟次数都是在非常合理的范围内。 这时我才意识到频繁定位的罪魁祸首并不在我们内部,而是第三方库搞的鬼。 那么问题来了,引入的第三方库那么多,我怎么知道谁的定位调用频率不合理呢? 虽然我在项目中的公共定位模块中打了log,但问题是第三方库可调不到我们内部的接口。 那么我们能不能到更底层的地方去埋点统计呢? AOP AOP,即面向切面编程,已经不是什么新鲜玩意了。 就我个人的理解,AOP就是把我们的代码抽象为层次结构,然后通过非侵入式的方法在某两个层之间插入一些通用的逻辑,常常被用于统计埋点、日志输出、权限拦截等等,详情可搜索相关的文章,这里不具体展开讲AOP了。

Java HashMap nested generics with wildcards

感情迁移 提交于 2019-12-28 00:19:27
问题 I'm trying to make a hashmap of hashmap values containing hashsets of different subclasses of a custom class, like so: HashMap<String, Hashmap<String, HashSet<? extends AttackCard>>> superMap AttackCard has subclasses such as: Mage , Assassin , Fighter . Each HashMap in the superMap will only ever have HashSets containing a single subclass of AttackCard . When I try putting a HashMap<String, HashSet<Assassin>> into superMap, I get a compiler error: below is the code where the error occurs: