StringBuilder.charAt() Method

by Chaitanya Singh August 28, 2014

Description public char charAt(int index): This method returns the character present at the specified index in the StringBuilder instance. The first char of StringBuilder is at index 0, second one is at index 1 and so on. The index argument must be greater than or equal to 0, and less than the length of the sequence, otherwise it would throw […]

Read the full article →

StringBuilder.capacity() Method

by Chaitanya Singh August 28, 2014

Description public int capacity(): Returns the current capacity. The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur. Example This example demonstrate the use of capacity() method of StringBuilder class. import java.lang.StringBuilder; class StringBuilderCapacity{ public static void main(String[] args) { StringBuilder sb = new StringBuilder("TEST STRING"); /* Capacity of newly created StringBuilder […]

Read the full article →

StringBuilder.append(char c) Method

by Chaitanya Singh August 28, 2014

Description public StringBuilder append(char c): This method appends representation of the char value(provided as an argument to this method, during call) to the StringBuilder instance. Example Here we are going to show two ways to append a char value to StringBuilder instance. We can directly append the char value to StringBuilder using append(char c) method or we can append it […]

Read the full article →

StringBuilder.append(boolean b) Method

by Chaitanya Singh August 28, 2014

Description public StringBuilder append(boolean b): This method appends the string representation of the boolean value(provided as an argument to this method, during call) to the StringBuilder sequence. Example This example shows two ways to append a boolean value to the StringBuilder. We can append the value directly by using boolean literal or by using boolean variable. In both the cases, […]

Read the full article →

how to copy one hashmap content to another hashmap

by Chaitanya Singh August 25, 2014

In this tutorial we are gonna learn how to copy one HashMap elements to another HashMap. We will be using putAll() method of HashMap class to perform this operation. Complete code as follows: import java.util.HashMap; class HashMapDemo{ public static void main(String[] args) { // Create a HashMap HashMap<Integer, String> hmap = new HashMap<Integer, String>(); //add elements to HashMap hmap.put(1, "AA"); […]

Read the full article →

HashMap – Get value from key example

by Chaitanya Singh August 25, 2014

Description Program to get value from HashMap when the key is provided. Example import java.util.HashMap; class HashMapDemo{ public static void main(String[] args) { // Create a HashMap HashMap<Integer, String> hmap = new HashMap<Integer, String>(); //add elements to HashMap hmap.put(1, "AA"); hmap.put(2, "BB"); hmap.put(3, "CC"); hmap.put(4, "DD"); // Getting values from HashMap String val=hmap.get(4); System.out.println("The Value mapped to Key 4 is:"+ […]

Read the full article →

Difference between HashSet and HashMap

by Chaitanya Singh August 21, 2014

In this article we are gonna discuss the differences between HashSet and HashMap classes. HashSet vs HashMap Differences: HashSet HashMap HashSet class implements the Set interface HashMap class implements the Map interface In HashSet we store objects(elements or values) e.g. If we have a HashSet of string elements then it could depict a set of HashSet elements: {“Hello”, “Hi”, “Bye”, […]

Read the full article →

Difference between HashSet and TreeSet

by Chaitanya Singh August 20, 2014

In this article we are gonna discuss the differences between HashSet and TreeSet. HashSet vs TreeSet 1) HashSet gives better performance (faster) than TreeSet for the operations like add, remove, contains, size etc. HashSet offers constant time cost while TreeSet offers log(n) time cost for such operations. 2) HashSet does not maintain any order of elements while TreeSet elements are […]

Read the full article →

How to convert a HashSet to a TreeSet

by Chaitanya Singh August 18, 2014

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 Strings and we are creating a TreeSet of strings by copying all the elements of HashSet to TreeSet. import java.util.HashSet; import java.util.TreeSet; import java.util.Set; class ConvertHashSettoTreeSet{ public static void main(String[] args) { // Create a […]

Read the full article →

Converting a HashSet to an Array

by Chaitanya Singh August 18, 2014

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 HashSet HashSet<String> hset = new HashSet<String>(); //add elements to HashSet hset.add("Element1"); hset.add("Element2"); hset.add("Element3"); hset.add("Element4"); // Displaying HashSet elements System.out.println("HashSet contains: "+ hset); // Creating an Array String[] array = new String[hset.size()]; hset.toArray(array); // Displaying Array […]

Read the full article →

Convert HashSet to a List/ArrayList

by Chaitanya Singh August 18, 2014

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 and we are creating an ArrayList of Strings by copying all the elements of HashSet to ArrayList. Following is the complete code: import java.util.HashSet; import java.util.List; import java.util.ArrayList; class ConvertHashSetToArrayList{ public static void main(String[] args) […]

Read the full article →

Our Friend's website link : FromDev.com