java random class tutorial

The java.util.Random class is used to generate random numbers. Java Random class objects are thread safe. It provides several methods to generate random numbers of type integer, double, long, float etc. Note: Random class objects are not suitable for security sensitive applications so it is better to use java.security.SecureRandom in these cases. Java Random class … Read more

Data structure tutorial

Data Structure The data structure is a particular way of organizing and storing data in a computer so that it can be accessed and modified efficiently. It is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data. Arrays, Linked List, Stack, Queue, etc., … Read more

Java doubly linked list implementation

Doubly linked list: Items can navigate in both forward and backword directions. Linked list operations Insertion: Adds an element at the beginning of the list. Deletion: Deletes an element at the beginning of the list. Display: Displays the complete list. Search: Searches an element using the given key. Delete: Deletes an element using the given … Read more

Java Singly linked list implementation

Singly linked list: Items can navigate in forward direction only. Linked list operations Insertion: Adds an element at the beginning of the list. Deletion: Deletes an element at the beginning of the list. Display: Displays the complete list. Search: Searches an element using the given key. Delete: Deletes an element using the given key. Linked … Read more

Java linked list tutorial

Linked list A linked list is a linear collection of data elements, in which linear order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is … Read more

Java deque implementation using doubly linked list

Deque Queue Double-ended queue is an abstract data type. A deque represents a linear collection of elements that support insertion, retrieval and removal of elements at both ends. Dequeue, often abbreviated to deque. Example package com.w3schools;   class Node<T>{ private Node<T> prev; private Node<T> next; private T value;   public Node<T> getPrev() { return prev; … Read more

Java PriorityQueue implementation

PriorityQueue Queue PriorityQueue extends AbstactQueue. PriorityQueue is a type of queue but not provide the FIFO facility to its elements. It not allows the null elements. A PriorityQueue is like a normal queue but each element has a priority associated with it. Example package com.w3schools;   public class Test { @SuppressWarnings("rawtypes") private Comparable[] pQueue; private … Read more

Java deque implementation

Deque Queue Double-ended queue is an abstract data type. A deque represents a linear collection of elements that support insertion, retrieval and removal of elements at both ends. Dequeue, often abbreviated to deque. This general data class has some possible sub-types: input-restricted deque: It is one where deletion can be made from both ends, but … Read more

Java dynamic queue implementation

Dynamic Queue As we discussed in previous example that a queue throws an exception if enough space is not available to accept an element to be pushed. To overcome this situation we can create dynamic queue whose capacity will keep increases as it reaches to max capacity. Example package com.w3schools;   public class Test { … Read more

Java queue implementation

Examples package com.w3schools;   public class Test { private int capacity; int queueArray[]; int front = 0; int rear = -1; int currentSize = 0;   public Test(int queueSize){ this.capacity = queueSize; queueArray = new int[this.capacity]; }   /** * Adds element at the end of the queue. * @param item */ public void enqueue(int … Read more