Description Program to convert a HashSet to a TreeSet Program Here is the complete code for HashSet to TreeSet conversion. We have a HashSet of… [Read More]
Archives for 2014
Converting a HashSet to an Array
Here is the program for converting a HashSet to an array. Program import java.util.HashSet; class ConvertHashSettoArray{ public static void main(String[] args) { // Create a… [Read More]
Convert HashSet to a List/ArrayList
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]
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 the last post we discussed the difference between StringBuffer and StringBuilder. Here we are gonna discuss the differences between String and StringBuffer class. String… [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]
- « Previous Page
- 1
- 2
- 3
- 4
- …
- 16
- Next Page »