Java Autoboxing and Unboxing with examples

by Chaitanya Singh September 2, 2014

Java 1.5 introduced a special feature of auto conversion of primitive types to the corresponding Wrapper class and vice versa. Autoboxing: Automatic conversion of primitive types to the object of their corresponding wrapper classes is known as autoboxing. For example – conversion of int to Integer, long to Long, double to Double etc. Unboxing: It is just the reverse process […]

Read the full article →

Java Annotations tutorial with examples

by Chaitanya Singh September 1, 2014

Java Annotations allow us to add metadata information into our source code, although they are not a part of the program itself. Annotations were added to the java from JDK 5. Annotation has no direct effect on the operation of the code they annotate (i.e. it does not affect the execution of the program). In this tutorial we are going […]

Read the full article →

Java Enum Tutorial with examples

by Chaitanya Singh September 1, 2014

An enum is a special type of data type which is basically a collection (set) of constants. In this tutorial we will learn how to use enums in Java and what are the possible scenarios where we can use them. This is how we define Enum public enum Directions{ EAST, WEST, NORTH, SOUTH } Here we have a variable Directions […]

Read the full article →

Java Regular Expressions (java regex) Tutorial with examples

by Chaitanya Singh August 31, 2014

Regular expressions are used for defining String patterns that can be used for searching, manipulating and editing a text. These expressions are also known as Regex (short form of Regular expressions). Lets take an example to understand it better: In the below example, the regular expression .*book.* is used for searching the occurrence of string “book” in the text. import […]

Read the full article →

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 →

Our Friend's website link : FromDev.com