What is Stack? Stack is a linear data structure that follows the specific order to perform the operations. For example, if we want to access the element in the array we can do it any time but in the case of stack data structure, there is only one sequence to access the element. In the stack, we insert the element from one end with push operation and delete the element from the same end using pop operation. The end of the stack used to perform all the operations is called the top of the stack. Therefore, a stack follows the LIFO (Last In First Out) principle, which means the element that is inserted last will be the first element to come out of the stack. The most important thing to remember in the stack data structure is that it stores the elements of the same data type only. Let us understand the condition to check whether the stack is empty for full: Condition to Check if Stack is Empty int Empty() { if (top ==- 1 ) return 1 ; else return 0 ; } Con...
How to Merge Two Arrays in Java There are following ways to merge two arrays: Java arraycopy() method Without using arraycopy() method Java Collections Java arraycopy() method public static void arraycopy(Object source, int source_position, Object destination, int destination_position, int length) Parameters source : It is a source array. source_position : Starting point in the source array. destination : It is a destination array. destination_position : Starting position in the destination array. length : The number of array elements to be copied import java.util.Arrays; public class MergeArrayExample1 { public static void main(String[] args) { int [] firstArray = { 23 , 45 , 12 , 78 , 4 , 90 , 1 }; //so...
Thread Pool A thread pool reuses previously created threads to execute current tasks and offers a solution to the problem of thread cycle overhead and resource thrashing. It is a software design pattern for achieving concurrency of execution in a computer program. Since the thread is already existing when the request arrives, the delay introduced by thread creation is eliminated, making the application more responsive. The size of a thread pool is the number of threads kept in reserve for executing tasks What does Static word in Java mean? Can we override a Static method? A member of a class that can be accessed without instantiating the object of the class. We cannot override static method in java since overriding is based on dynamic binding at runtime and static members are bound at compile time Can abstract class have static methods? If we declare a method in a class abstract to use it, we must override this method in the subclass. But,...
Comments
Post a Comment