- 浏览: 1115616 次
文章分类
- 全部博客 (379)
- S2SH (16)
- stuts2 (0)
- java语言 (81)
- JSP (17)
- <html>元素 (11)
- javaweb (4)
- web容器 (3)
- ext (23)
- javaScript (48)
- ant (1)
- liferay (1)
- sql (9)
- css (42)
- 浏览器设置 (3)
- office_world (1)
- eclipse (4)
- 其它 (28)
- 操作系统 (5)
- android (6)
- Struts2 (11)
- RegEx (3)
- mysql (5)
- BigDATA (1)
- Node.js (1)
- Algorithm (10)
- Apache Spark (1)
- 数据库 (5)
- linux (2)
- git (1)
- Adobe (3)
- java语言,WebSocket (1)
- Maven (3)
- SHELL (1)
- XML (2)
- 数学 (2)
- Python (2)
- Java_mysql (1)
- ReactJS (6)
- 养生 (4)
- Docker (1)
- Protocols (3)
- java8 (2)
- 书籍 (1)
- Gradle (2)
- AngularJS (5)
- SpringMVC (2)
- SOAP (1)
- BootstrapCSS (1)
- HTTP协议 (1)
- OAuth2 (1)
最新评论
-
Lixh1986:
Java并发编程:自己动手写一把可重入锁https://blo ...
Java之多线程之Lock与Condition -
Lixh1986:
http://win.51apps.com.cn/https: ...
temp -
ztwsl:
不错,支持很好
HttpServletRequest和ServletRequest的区别 -
guodongkai:
谢谢您能将知识精华汇编总结,让初学者们从原理中学会和提高。
javaScript之function定义 -
kangwen23:
谢谢了,顶顶
struts2中的ValueStack学习
Collections:
1.Why Map interface doesn’t extend Collection interface?
2.What is difference between HashMap and Hashtable?
3.Differences between comparable and comparator?
Comparable
A comparable object is capable of comparing itself with another object. The class itself must implements the java.lang.Comparable interface in order to be able to compare its instances.
Comparator
A comparator object is capable of comparing two different objects. The class is not comparing its instances, but some other class’s instances. This comparator class must implement the java.util.Comparator interface.
4.How can we sort a list of Objects?
5.What is difference between fail-fast and fail-safe?
6. What is difference between Iterator ,ListIterator and Enumeration?
7.What is difference between Set and List in Java?
8.Differences between arraylist and vector?
9.What are the classes implementing List interface?
10. Which all classes implement Set interface ?
11.How to make a collection thread safe?
12.Can a null element added to a TreeSet or HashSet?
13. Explain Collection’s interface hierarchy?
14.Which design pattern Iterator follows?
15.Which data structure HashSet implements
16.Why doesn't Collection extend Cloneable and Serializable?
17.What is the importance of hashCode() and equals() methods? How they are used in Java?
18.What is difference between array & arraylist?
19.What is the Properties class?
20.How to convert a string array to arraylist?
21.Difference between HashMap and TreeMap?
______________________________________________________________
- 转自:http://www.instanceofjava.com/2015/07/collections-interview-questions-java.html
-
1.Why Map interface doesn’t extend Collection interface?
- Set is unordered collection and does not allows duplicate elements.
- List is ordered collection allows duplicate elements.
- Where as Map is key-value pair.
- It is viewed as set of keys and collection of values.
- Map is a collection of key value pairs so by design they separated from collection interface.
2.What is difference between HashMap and Hashtable?
- Synchronization or Thread Safe
- Null keys and null values
- Iterating the values
- Default Capacity
3.Differences between comparable and comparator?
- Comparable Interface is actually from java.lang package.
- It will have a method compareTo(Object obj)to sort objects
- Comparator Interface is actually from java.util package.
- It will have a method compare(Object obj1, Object obj2)to sort objects
Comparable
A comparable object is capable of comparing itself with another object. The class itself must implements the java.lang.Comparable interface in order to be able to compare its instances.
Comparator
A comparator object is capable of comparing two different objects. The class is not comparing its instances, but some other class’s instances. This comparator class must implement the java.util.Comparator interface.
4.How can we sort a list of Objects?
- To sort the array of objects we will use Arrays.sort() method.
- If we need to sort collection of object we will use Collections.sort().
5.What is difference between fail-fast and fail-safe?
- Fail fast is nothing but immediately report any failure. whenever a problem occurs fail fast system fails.
- In java Fail fast iterator while iterating through collection of objects sometimes concurrent modification exception will come there are two reasons for this.
- If one thread is iterating a collection and another thread trying to modify the collection.
- And after remove() method call if we try to modify collection object
6. What is difference between Iterator ,ListIterator and Enumeration?
- Enumeration interface implemented in java 1.2 version.So Enumeration is legacy interface.
- Enumeration uses elements() method.
- Iterator is implemented on all Java collection classes.
- Iterator uses iterator() method.
- Iterator can traverse in forward direction only.
- ListIterator is implemented only for List type classes
- ListIterator uses listIterator() method.
7.What is difference between Set and List in Java?
- A set is a collection that allows unique elements.
- Set having no index.
- Set allows only one null value.
- Set having classes like : HashSet
- List having index.
- List allows n number of null values.
- List will display Insertion order with index.
- List having classes like : Vector
LinkedHashMap
TreeSet
ArrayList
LinkedList
8.Differences between arraylist and vector?
- Vector was introduced in first version of java . that's the reason only vector is legacy class.
- ArrayList was introduced in java version1.2, as part of java collections framework.
- Vector is synchronized.
- ArrayList is not synchronized.
9.What are the classes implementing List interface?
- ArrayList
- LinkedList
- Vector
10. Which all classes implement Set interface ?
- HashSet
- LinkedHashSet
- TreeSet
11.How to make a collection thread safe?
- Vector, Hashtable, Properties and Stack are synchronized classes, so they are thread-safe and can be used in multi-threaded environment.
- By using java.util.Collections.synchronizedList(list) we can make list classes thread safe.
- By using java.util.Collections.synchronizedSet(set) we can make set classes thread safe.
12.Can a null element added to a TreeSet or HashSet?
- One null element can be added to hashset.
- TreeSet also allow null value once.
13. Explain Collection’s interface hierarchy?
14.Which design pattern Iterator follows?
- Iterator design pattern
15.Which data structure HashSet implements
- Hashset implements hashmap internally.
16.Why doesn't Collection extend Cloneable and Serializable?
- List and Set and queue extends Collection interface.
- SortedMap extends Map interface.
17.What is the importance of hashCode() and equals() methods? How they are used in Java?
- equals() and hashcode() methods defined in "object" class.
- If equals() method return true on comparing two objects then hashcode() of those two objects must be same.
18.What is difference between array & arraylist?
- Array is collection of similar type of objects and fixed in size.
- Arraylist is collection of homogeneous and heterogeneous elements.
19.What is the Properties class?
- Properties is a subclass of Hashtable. It is used to maintain lists of values in which the key and the value is String.
20.How to convert a string array to arraylist?
- Using java.util.Arrays.asList();
import java.util.Arrays; import java.util.List; import java.util.ArrayList; public class StringArrayTest { public static void main(String[] args) { String[] words = {"ace", "boom", "crew", "dog", "eon"}; List<String> wordList = Arrays.asList(words); for (String e : wordList) { System.out.println(e); } } }
21.Difference between HashMap and TreeMap?
- TreeMap is an example of a SortedMap, which means that the order of the keys can be sorted, and when iterating over the keys, you can expect that they will be in order.
- HashMap on the other hand, makes no such guarantee. Therefore, when iterating over the keys of a HashMap, you can't be sure what order they will be in.
- HashMap is more time-efficient. A TreeMap is more space-efficient.
- TreeMap only works with Comparable objects, HashMap only works with objects with a suitable hashCode() implementation.
______________________________________________________________
- 转自:http://www.instanceofjava.com/2015/07/collections-interview-questions-java.html
-
发表评论
-
java 将文件夹所有的文件合并到指定的文件夹下
2020-06-30 19:17 1082场景:将文件夹所有的文件合并到指定的文件夹下 另外:如果想效 ... -
多线程-线程池的四种创建方式
2020-04-01 18:38 506多线程-线程池的四种创建方式 https://blog.cs ... -
Java基础之:nio
2019-11-13 15:38 499一、理论讲解: 史上最强Java NIO入门:担心从入门到放弃 ... -
Java 分布式之:RPC 基本概念
2019-11-13 15:07 476转载: https://www.jianshu.com/p/ ... -
Java之 volatile 关键字原理详解
2019-11-07 15:36 565一、什么是 volatile ? ... -
POI实现excell批注背景图片(仿html浮窗显示图片)
2019-10-21 08:17 714POI实现excell批注背景图片(仿html浮窗显示图片) ... -
Java之设计模式之 Observer 观察者
2019-07-04 17:21 1092观察者设计模式 Java 已经实现了该模式,并且提供了使用类 ... -
HashMap, LinkedHashMap and TreeMap
2019-03-01 11:04 684https://stackoverflow.com/a/177 ... -
Java lib 操作 excel 插入图片
2019-01-19 12:46 882https://poi.apache.org/componen ... -
数据库连接池C3P0
2018-05-29 16:50 906一、名字的由来 很多 ... -
Java8之集合(Collection)遍历 forEach()、stream()
2018-05-29 14:39 20758package java8.collections; ... -
Junit Vs main on "java.util.concurrent.Executors"
2017-11-10 16:44 836Same code with different result ... -
Java之大数据学习路线
2017-11-03 10:08 5727三个月大数据研发学习 ... -
Java中创建对象的5种方式
2017-10-26 14:21 843一、Java之5种创建对象的方式 ————————————— ... -
Log4j和Slf4j的比较
2017-06-23 12:41 1418一直搞不清 Log4j 和 SLF4j 的关系。今天才若有所 ... -
Java之Java7新特性之try资源句式
2017-04-20 14:58 5388Java之Java7新特性之try资源句式 一、【try资源 ... -
Java之 java.util.concurrent 包之ExecutorService之submit () 之 Future
2017-03-04 21:27 3843一、如何使用 ExecutorService.submit() ... -
Java之 java.util.concurrent 包之Executor与ExecutorService
2017-03-04 21:18 2707一、问题: execute() 与 submit() 的区别? ... -
JAVAEE之单用户登录
2017-02-05 11:55 1062单用户登录是系统中数据一直性的解决方案之一。 问题背景: 试 ... -
Java之多线程之线程池之线程重复使用
2017-02-04 13:33 5574一、问题背景 在使用多线程时,如果要开启一个任务,则就需要新 ...
相关推荐
### Java Collections Framework 1016 #### 一、教程概览 本教程由developerWorks提供,旨在深入探讨Java Collections Framework。它不仅适用于初学者,也适合具有一定经验的开发人员。教程从简单的编程示例开始,...
java jar包,亲测试可用 安全,可以对其进行数字签名,只让能够识别数字签名的用户使用里面的东西。 加快下载速度; 压缩,使文件变小,与ZIP压缩机制完全相同。 包封装。能够让JAR包里面的文件依赖于统一版本的...
java jar包,亲测试可用 安全,可以对其进行数字签名,只让能够识别数字签名的用户使用里面的东西。 加快下载速度; 压缩,使文件变小,与ZIP压缩机制完全相同。 包封装。能够让JAR包里面的文件依赖于统一版本的...
java jar包,亲测试可用 安全,可以对其进行数字签名,只让能够识别数字签名的用户使用里面的东西。 加快下载速度; 压缩,使文件变小,与ZIP压缩机制完全相同。 包封装。能够让JAR包里面的文件依赖于统一版本的...
java jar包,亲测试可用 安全,可以对其进行数字签名,只让能够识别数字签名的用户使用里面的东西。 加快下载速度; 压缩,使文件变小,与ZIP压缩机制完全相同。 包封装。能够让JAR包里面的文件依赖于统一版本的...
Java智力题是考察开发者逻辑思维能力和基础编程素养的重要方式,特别是在面试或笔试环节。这份"JAVA-Puzzles-section.zip"压缩包中包含了一份名为"智力题部分.doc"的文档,很可能是整理了一些与Java相关的逻辑谜题和...
"java-test.zip_java面试题"这个压缩包文件正是为此目的而准备的,它包含了多家大型企业的经典面试题目,帮助求职者们在面试前做好充分的准备。 "享受一种生活 java面试题及答案(基础题122道,代码题19道).htm"这...
### JAVA-SSH面试题知识点详解 #### Java基础知识 1. **面向对象的特征** - **抽象** 抽象是面向对象编程的核心概念之一,指的是在设计阶段仅关注对象的关键属性和行为,忽略不必要的细节。它可以帮助我们构建...
数据挖掘18大算法实现以及其他相关经典DM算法 算法可视化 All Algorithms implemented in Java. All Algorithms implemented in Python. 设计模式 java设计模式 - Design patterns implemented in Java 人工智能 An ...
8. **Java API**:熟悉常用的Java类库,如String、Date、Collections、Math等,以及常用的数据结构和算法。 9. **Java Swing或JavaFX**:对于GUI编程,考生可能需要了解如何使用Swing库创建桌面应用程序,或者使用...
### Java 开发实战经典课后习题答案知识点总结 #### Java 简介 - **文件后缀**: Java源程序文件的后缀是`.java`,而编译后生成的Java字节码文件的后缀为`.class`。 - **程序入口**: Java程序的执行总是从`main()`...
java jar包,亲测试可用 安全,可以对其进行数字签名,只让能够识别数字签名的用户使用里面的东西。 加快下载速度; 压缩,使文件变小,与ZIP压缩机制完全相同。 包封装。能够让JAR包里面的文件依赖于统一版本的...
Java编程语言中的知识点涵盖广泛,这里我们主要讨论标题和描述中提到的一些重点: 1. **final, finally, finalize的区别** - `final` 关键字用于声明不可变的类、变量或方法。对于类,一旦声明为final,就不能被...
"2014-蓝桥杯预赛-Java本科-B组真题"是针对Java编程语言的一次竞赛,旨在测试参赛者在Java编程、数据结构、算法应用等方面的技能。蓝桥杯比赛通常涵盖多轮,预赛是第一阶段,旨在筛选出在软件开发和问题解决方面有...
Java语言提供了丰富的库支持,如Collections.sort()用于排序,而我们还需要理解和掌握基本的算法思想,如分治法、动态规划、贪心算法和回溯法。文件中的学习资料可能包括经典的排序算法(冒泡、插入、选择、快速、...
标题中的“java-leetcode题解之第972题最接近原点的K个点”表明这是一份关于使用Java编程语言解决LeetCode在线编程挑战平台上的第972题的解决方案。LeetCode是一个广受欢迎的网站,程序员们在上面通过解决算法问题来...