Difference between HashSet and TreeSet in Java

Difference between HashSet and TreeSet in Java
There are several differences between an HashSet and a TreeSet is similar to what we discussed as a difference between TreeMap and HashMap. Anyway, Set and Map are two completely different interfaces so we will revisit those differences here. Probably the most important difference between HashSet and TreeSet is the performance. HashSet is faster than TreeSet which means if you need performance use HashSet but HashSet doesn't provide any kind of ordering so if you need ordering then you need to switch to TreeSet which provides sorting of keys. Sorting can be natural order defined by a Comparable interface or any particular order defined by Comparator interface in Java.

How to Increase Heap Size of Java Program running in Eclipse

It is possible to increase the heap size allocated by the JVM by using command line options Here we have 3 options

-Xms<size>        to set the initial Java heap size
-Xmx<size>        to set the maximum Java heap size
-Xss<size>          to set the java thread stack size

$ java -Xms1G -Xmx2G MainClass

In the above line, we have set the minimum heap size to 1GB and maximum heap size to 2GB.

How to convert Vector to array in Java? 2 Examples

In the last article, we have learned how to convert a LinkedList to array in Java and in today's tutorial you will learn how to convert a Vector to array in Java. There is a similarity between Vector and LinkedList, both implements the List interface. Even though Vector is a legacy class and exists in Java from JDK 1.1 long before Java Collection framework was introduced, it was later retrofitted to implement the List interface. You can use the same toArray() method to convert a Vector to an array in Java. Similar to LinkedList, you can convert Vector of any object to an array of the corresponding object, the only restriction is that you cannot convert a vector of Integers to an array of ints or Vector of Float objects to an array of floats, which applies to our linked list solution as well.