Category: java
Java Constructor Tutorial – Why do we need Constructors ?
In this article we will discuss need and usage details of constructors in Java. What is a Constructor ? Constructor is a member function of the class that is used to initialize a newly constructed object i.e. initializing the member variables of object. Advertisements It has the same name as of the class. Why do …
Java Constructor Tutorial – Why do we need Constructors ?Read More
How to add elements in a LinkedList in Java
In this article we will discuss how to add elements in LinkedList and then display them. Lets create a LinkedList of String i.e. Advertisements List<String> listOfStr = new LinkedList<>(); To add elements in LinkedList we will use its add() function i.e. boolean add(E e) add() member function of LinkedList always appends the element in the …
What is an Exception and How to do Exception Handling in Java
In this article we will discuss what is an exception in Java and how to handle exception in Java. What is an exception in Java An error occurred at runtime in a Java Application is called an Exception. If a triggered Exception is not handled then it will cause the application to crash. Checkout following …
What is an Exception and How to do Exception Handling in JavaRead More
Java LinkedList Tutorial
LinkedList is a kind of List used to store elements. Its an ordered collection i.e. elements added at a position in LinkedList will remain in that position till modified by user. It internally uses a doubly linked list datastructure implementation i.e. each element is stored at separate node. Each node has a reference to previous and …
How to add elements at a particular index in LinkedList
In this article we will discuss how to add elements at a particular index or position in a LinkedList in Java. add() member function of LinkedList always appends the element at the end of LinkedList. Now suppose we don’t want to add element at the end of Linked List instead of it we want to add element somewhere …
How to add elements at a particular index in LinkedListRead More
How to iterate over a LinkedList in Java
In this article we will discuss how to iterate over a LinkedList Collection in Java and access objects. To fetch the Iterator from a LinkedList object use following member function, Advertisements ListIterator<E> listIterator(); It will return ListIterator object that implements Iterator that provides functions to iterate over the LinkedList object. It manages an internal Cursor which is …
How to iterate LinkedList in reverse or backward direction
In this article we will discuss how to iterate over a LinkedList in reverse order. Method 1 : Using Descending Iterator Iterator<E> descendingIterator() Descending Iterator returns the Iterator that points to the end of of List i.e. LinkedList<String> listOfStr = new LinkedList<>(); // Get Descending List Iterator from List Object Iterator<String> listItReverse = listOfStr.descendingIterator(); Now calling function …
How to iterate LinkedList in reverse or backward directionRead More
How to create and add elements in a HashSet in Java
+In this article we will discuss how to create a HashSet of integers and add elements in it. Creating a HashSet Object for integer // Create a HashSet of int HashSet<Integer> setOfInts = new HashSet<>(); This hashset object can contain only unique integers. Advertisements Adding Element in a HashSet To add an element in a …
How to create and add elements in a HashSet in JavaRead More
What is Hashing and Hash Table?
What is Hashing ? Hashing is a technique used to store elements in such a way that searching over them should be very fast. It internally uses a Hash Table to store the elements. What is Hash Table ? Hash Table is a kind of Data Structure Used to achieve Hashing. It internally maintains a …
How to Merge two HashSets in Java
In this article we will discuss how to merge two HashSets. HashSet provides a member function addAll() i.e. Advertisements public boolean addAll(Collection<? extends E> c) It provides a functionality to add a collection into to a HashSet. But this Collection should be of Same Type as of HashSet or of its Base Class. How addAll() works It …