Tag: Java
How to convert a HashSet into an array in Java
In this article we will discuss how to convert a HashSet in to an array. Each collection that provides a member function toArray() i.e. Advertisements public <T> T[] toArray(T[] a) It iterates through all the elements of Collection (HashSet in our case) and set the each elements in the passed argument array []a. But if array …
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 …
How to Merge an Array in a HashSet in Java
In this article we will discuss how to merge an array in a HashSet HashSet has a member function addAll() that can add a collection into to a HashSet. But this Collection should be of Same Type as of HashSet or of its Base Class. Advertisements public boolean addAll(Collection<? extends E> c)  It will add the each …
How to Search for an element in HashSet in Java
In this article we will discuss how to search for an element in HashSet. Main feature of a HashSet is Fast searching. Which it achieves using Hashing. Now suppose we want to search if an element exists in HashSet ? Advertisements It can be done using contains() member function of HashSet i.e. // It checks if the given …
How to iterate over a HashSet in Java
In this article we will discuss how to Iterate over a HashSet in Java using HashSet. Fetch Iterator from HashSet To iterate over a HashSet we will use an Underlying Iterator object of the HashSet. Advertisements Fetch the Iterator from a HashSet object use its member function iterator() i.e. // Create a HashSet of String HashSet<String> …
For loop with 2 variables in C++ and Java
In this article we will discuss how to use for loop with two variables. For loop is basic feature we use in programming. In it we use a variable and keep on increasing or decreasing it till a condition is matched. Advertisements But many times a scenario comes where we want to increment or decrement two variables …
Capitalize First letter of each word in a String in Java | Camel Case
In this article we will discuss how to capitalize first letter of each word in a String.Suppose given string is, this is the sample string Now after converting first letter of each word, string will become, This Is The Sample String This type of String is also called Camel Case. Advertisements Algorithm For Capitalizing First Letter …
Capitalize First letter of each word in a String in Java | Camel CaseRead More
How to Create a Thread in Java using Runnable Interface
In this article we will discuss how to create a thread in Java using Runnable Interface. Why do we need Runnable Interface We create threads to execute certain tasks in parallel. Every task is different from another Task. Tasks are usually encapsulated in its own class. Therefore, extending our Task class from Thread is not only an incorrect …
How to Create a Thread in Java using Runnable InterfaceRead More
How to call Base class’s overridden method from Derived class in java
In this article we will discuss how to call parent class’s overridden method from a derived class method in Java. Suppose we have a Base class which has a function display() i.e. Advertisements class Base { public void display() { System.out.println(“Base :: display”); } } Now we will create a Derived class that will extend this …
How to call Base class’s overridden method from Derived class in javaRead More
Method Overriding in Java – Tutorial and Example
In this article we will discuss, what is method overriding in Java. What is a Method Overriding in Java? When a Derived class overrides a method of its Base class then its called Method overriding. Advertisements Why do we need of method overriding in Java? Every method in a class represents some behavior. For example, We have …