How to convert LinkedList to array in Java? Example

You can convert a LinkedList to an array in Java by using the toArray() method of LinkedList. The toArray() method accepts an array of relevant type to store contents of LinkedList. It stores the elements in the same order they are currently inside LinkedList. By using the toArray() method you can convert any type of LinkedList e.g. Integer, String or Float to any type of Array, only catch is this you cannot convert a LinkedList to an array of primitives i.e. a LinkedList of Integer cannot be converted into an array of ints by using using toArray() method, but you can convert it to array of Integer objects, that's perfectly ok. Similarly, you can convert LinkedList of Double to an array of Double and LinkedList of Float objects to an array of floats.

What is Inheritance in Java with example - Object Oriented Programming Tutorial

What is Inheritance in Java
Inheritance in Java or OOPS (Object oriented programming) is a feature which allows coding reusability.  In other words, Inheritance  self-implies inheriting or we can say acquiring something from others. Along with Abstraction, Encapsulation and Polymorphism, Inheritance forms the backbone of Object oriented programming and Java.  In Java, we use the term inheritance when one object acquires some property from other objects. In Java, inheritance is defined in terms of superclass and subclass. it is normally used when some object wants to use existing feature of some class and also want to provide some special feature, so we can say inheritance has given the advantage of reusability.

How to loop over TreeSet in Java with example

In our earlier articles, we have learned how to loop over ArrayList in Java and you can use the same logic to loop over a TreeSet. You can use both, enhanced for loop and Iterator to traverse over TreeSet in Java. Though, worth noting is that Iterator returned by the iterator() method of TreeSet returns elements in the sorted order which is imposed by the Comparator you have provided to TreeSet at the time of instantiation. By default, if you don't provide any custom Comparator than TreeSet sorts elements in their natural order e.g. String elements are sorted in alphabetic order and Integer elements are sorted in numeric order. When you iterate over a TreeSet the iterator follows this order.