In this tutorial we will be learning how to convert a HashSet to a List (ArrayList). Program Here we have a HashSet of String elements… [Read More]
Archives for 2014
Delete all the elements from HashSet
Here we are gonna see how to remove all the elements of HashSet in one go. We can do so by calling clear() method of… [Read More]
How to copy one Set to another Set
In this article we are gonna see an example program to copy one Set to another Set. Example In this example we are copying one… [Read More]
How to Iterate over a Set/HashSet
There are following two ways to iterate through HashSet: 1) Using Iterator 2) Without using Iterator Example 1: Using Iterator import java.util.HashSet; import java.util.Iterator; class… [Read More]
Difference between String and StringBuffer
In this article, we will discuss the difference between String and StringBuffer. Both of these classes used to handle sequence of characters. However they are… [Read More]
Difference between StringBuilder and StringBuffer
In this article we are gonna discuss the differences between StringBuilder and StringBuffer. Before discussing the differences, lets have a look at what java documentation… [Read More]
Java StringBuffer substring()
In this tutorial, we will discuss the Java StringBuffer substring() method with the help of examples. The syntax of substring() method is: sb.substring(4) //substring starting… [Read More]
Java StringBuffer replace()
In this tutorial, we will discuss Java StringBuffer replace() method with the help of examples. Syntax of replace() method: //replace substring from index 4 to… [Read More]
StringBuilder append() null values as “null” String
While working with StringBuilder you may have come across a strange behaviour of append() method for null values. If you append a null value to… [Read More]
How to append a newline to StringBuilder
There are following two ways to append a new Line to a StringBuilder object:1) StringBuilder.append(“\n”);2) StringBuilder.append(System.getProperty(“line.separator”)); Example In this example we have a StringBuilder object… [Read More]
Java – Get Set view of Keys from HashMap
Description Program to get the Set of keys from HashMap. Example import java.util.Iterator; import java.util.HashMap; import java.util.Set; class HashMapExample{ public static void main(String args[]) {… [Read More]
How to check if a HashMap is empty or not?
Description Program to check if a HashMap is empty or not. We are using isEmpty() method of HashMap class to perform this check. Program import… [Read More]
Clone a HashMap in Java
Description A program to clone a HashMap. We will be using following method of HashMap class to perform cloning. public Object clone(): Returns a shallow… [Read More]
Java – LinkedList peek(), peekFirst() and peekLast() methods
Description public E peek(): Retrieves, but does not remove, the head (first element) of this list. public E peekFirst(): Retrieves, but does not remove, the… [Read More]
Java – LinkedList poll(), pollFirst() and pollLast() methods
Description Example Programs for poll(), pollFirst() and pollLast() methods of LinkedList class. LinkedList.poll() Retrieves and removes the head (first element) of this list. import java.util.LinkedList;… [Read More]
- « Previous Page
- 1
- 2
- 3
- 4
- …
- 16
- Next Page »