Blog

Map in Java Collection

A Map is an object that maps keys to values. A map cannot contain duplicate keys. Each key can map to at most one value. It models the mathematical function abstraction. A map contains values on the basis of key, i.e. key and value pair. Each key and value pair is known as an entry. A Map contains unique keys. A Map is…

Java.util.Arrays.binarySearch() Method

Binary search is used to search a key element from multiple elements. Binary search is faster than linear search. In case of binary search, array elements must be in ascending order. If you have unsorted array, you can sort the array using Arrays.sort(arr) method. Arrays.binarySearch() is the simplest and most efficient method to find an element in a…

java.util.Arrays

The java.util.Arrays class contains a static factory that allows arrays to be viewed as lists.Following are the important points about Arrays − This class contains various methods for manipulating arrays (such as sorting and searching). The methods in this class throw a NullPointerException if the specified array reference is null.  Comparing arrays: For comparing arrays and slices…

Collections in Java

The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects. Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion Java Collection means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue,…

GARBAGE COLLECTION

In Java, the programmer need not to care for all those objects which are no longer in use. Garbage collector destroys these objects. Garbage collector is best example of Daemon thread as it is always running in background. Main objective of Garbage Collector is to free heap memory by destroying unreachable objects. NOTE: Java garbage collection is the process…

Java String compareTo()

The Java String compareTo() method compares two strings lexicographically (in the dictionary order). The comparison is based on the Unicode value of each character in the strings. The syntax of the compareTo() method is: Here, string is an object of the String class. compareTo() Return Value returns 0 if the strings are equal returns a negative integer if the string comes before the str argument in the…

JAVA STRING METHODS

The String class has a set of built-in methods that you can use on strings. Java String length(): The Java String length() method returns the length of the string. The syntax of the length() method is: Here, string is an object of the String class. Java String charAt(): The Java String charAt() method returns the character at the specified index. The…

Why String Is Immutable?

In java, string objects are immutable. Immutable simply means unmodifiable or unchangeable. Once string object is created its data or state can’t be changed but a new string object is created. Requirement of String Pool: String pool (String intern pool) is a special storage area in Method Area. When a string is created and if the string…

RECURSION IN JAVA

Recursion in java is a process in which a method calls itself continuously. A method in java that calls itself is called recursive method. It makes the code compact but complex to understand. SAMPLE PROGRAM: public class Fact5{public static void main(String[]args){Fact5 f = new Fact5();f.printNumbers(1); }public void printNumbers(int i){System.out.print(i+” “);i++;if(i<6)printNumbers(i);} } OUTPUT: c:\java>java Fact51 2…

ONE-DIMENSIONAL ARRAY

The array is a data type in Java. It is a collection of similar type of elements that have contiguous index based memory location. We can use one-dimensional array to store a fixed set of elements(single dimension) in Java programming language. Always, Array index is starting from 0, not 1 Array index ending at n-1(n denotes array length) Array length(size) starts from 1 and…

Loading…

Something went wrong. Please refresh the page and/or try again.


Follow My Blog

Get new content delivered directly to your inbox.

Design a site like this with WordPress.com
Get started