Tags / Java
What is a diamond operator?
This is an improvement appeared in Java 7. Consider you have a class with a long name and you need to create a HashMap of Strings and Lists of your class instances. You code will look like this: In Java 7 you can write less code using the diamond operator(< > ):
What data can be stored in a collection?
You can store anything but primitives. To store primitives consider using wrappers (Integer for int, Double for double, etc…). For example, you can store your own classes: To store primitives: Notice, that you can add primitives, since it will be wrapped automatically:
What benefits does JCF provide?
Java Collections Framework provides the following benefits: Reduces programming effort: you don’t need to invent the wheel anymore, JCF provides useful data structures and algorithms. Increases program speed and quality: JCF provides high-performance, high-quality implementations of useful data structures and…
Whas is a collection?
Collection is an object that groups multiple elements into a single unit. Collections are used to store, retrieve and manipulate data. Live example: several Employee objects can be grouped into a collection: Java has a Java Collection Framework (JCF), which consists of: Interfaces - these are abstract data types that…
Java exceptions handling order
Consider there is a method which can throw IOException and FileNotFoundException. Is there a difference in which order we catch these exceptions in a single try-catch block? Will this code work correctly? The answer is NO. If you handle IOException first, you will never reach FileNotFoundException handling block…
Java Collections hierarchy
(Self-explanatory image above)
Describing the Java Set collection interface
A Set is a Collection that cannot contain duplicates. The Set interface extends Collection interface but has no specific methods. It adds the restriction that duplicates are prohibited. This interface also adds a stronger contract on the behavior of the equals and the hashcode methods, allowing Set instances to be…