HTML

How to convert comma separated String to ArrayList in Java - Example Tutorial

Suppose you have a comma separated list of String e.g. "Samsung, Apple, Sony, Google, Microsoft, Amazon" and you want to convert it into an ArrayList containing all String elements e.g. Samsung, Apple, Google etc. How do you do that? Well, Java doesn't provide any such constructor or factory method to create ArrayList from delimited String, but you can use String.split() method and Arrays.asList() method together to create an ArrayList from any delimited String, not just comma separated one. All you need to do is first split the given String on delimiter e.g. comma using the split() method, this will give you an array of String. Now, you can pass that array to Arrays.asList() method to create a List, but remember this would be fixed length list and not truly an ArrayList.

How to create ConcurrentHashSet from ConcurrentHashMap in Java 8 - Example Tutorial

There is no ConcurrentHashSet in JDK 8 but you can still create one for yourself by using the ConcurrentHashMap class of java.util.concurrent package. There is a new method added into ConcurrentHashMap in JDK 8, newKeySet(), which allows you to create a concurrent hash set backed by a concurrent hash map. If you remember whenever you get keys from the map they are returned in a Set e.g. for the old keySet() method because map only has unique keys. Since map doesn't allow duplicate keys, it can be used as a set, as long as you only care for keys or just one element. That's why Java designers are added newKeySet() method to convert a map to set. This is also a static method, which means you don't need a ConcurrentHashMap object to create a concurrent hash set.

Top 10 Java HashMap Interview Questions and Answers

The java.util.HashMap is one of the workhorses of JDK. Along with ArrayList, it is one of the most used classes from Java's collection framework. There is hardly a real world Java project, where I haven't seen the use of HashMap. It is an implementation of hash table data structure and it's not a surprise that HashMap is so useful, as someone has rightly said, "if you could have just one data structure, make it a hash table". The hash table data structure allows you to search for a value in O(1) time if you have key. In Java, there are several implementations of hash table data structure exists e.g. Hashtable, ConcurrentHashMap, LinkedHashMap etc but HashMap is your general purpose map. Though, if you have a special need you can use other hash table implementations available in JDK.

5 Free SQL Books For Beginners and Experienced - Download PDF or Read Online

There is no doubt that SQL is one of the most important skills for both programmers and business analyst. Since many Enterprise applications use the relational database at their backend e.g. Oracle, Microsoft SQL Server, MySQL, it's important to know SQL to work with data resided on those databases. SQL has been around for many years and it will be around for many more coming years. It is also one of the matured technology, hence there are a lot of free resources e.g. books, articles, tutorials are available online.   I have been sharing some free eBooks on different technologies e.g. Java, Python, and jQuery and today I'll share some of the free SQL books for online and offline reading.

Java 8 Default Methods FAQ - Frequently asked Questions and Answers

In last a couple of articles, I have to talk about default methods introduced in JDK 8. First, we have learned what is default method and why it is introduced in Java. Then we have seen the example of how you can use default methods to evolve your interface. After that we have analyzed does Java really support multiple inheritances now in JDK 8 (see here) and how will Java handle the diamond problem that will arise due to default methods. For example, what will happen if a class extend a class and implement an interface and both contain a concrete method with same method signature? Will a diamond problem arise? How will Java handle that and how you can solve it, and the difference between abstract class and interface in Java 8?  Once you went through those articles, you would have a good knowledge of default methods in Java 8.