Programming Articles

Page 1537 of 2547

How to generate a random BigInteger value in Java?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 3K+ Views

To generate random BigInteger in Java, let us first set a min and max value −BigInteger maxLimit = new BigInteger("5000000000000"); BigInteger minLimit = new BigInteger("25000000000");Now, subtract the min and max −BigInteger bigInteger = maxLimit.subtract(minLimit); Declare a Random object and find the length of the maxLimit: Random randNum = new Random(); int len = maxLimit.bitLength();Now, set a new B integer with the length and the random object created above.Exampleimport java.math.BigInteger; import java.util.Random; public class Demo {    public static void main(String[] args) {       BigInteger maxLimit = new BigInteger("5000000000000");       BigInteger minLimit = new BigInteger("25000000000");     ...

Read More

Remove a value from Java LinkedHashMap

Samual Sam
Samual Sam
Updated on 11-Mar-2026 2K+ Views

Use the remove() method to remove a single value from LinkedHashMap −At first, create a LinkedHashMap and add some elements −LinkedHashMap l = new LinkedHashMap(); l.put("1", "Jack"); l.put("2", "Tom"); l.put("3", "Jimmy"); l.put("4", "Morgan"); l.put("5", "Tim"); l.put("6", "Brad");Now, let’s say you need to remove the element 2 from the LinkedHashMap. For that, use the remove() method −Object ob = l.remove("2");The following is an example to remove a value from LinkedHashMap in Java −Exampleimport java.util.*; public class Demo { public static void main(String[] args) { LinkedHashMap l = new LinkedHashMap(); ...

Read More

What is Default access level in Java?

Jai Janardhan
Jai Janardhan
Updated on 11-Mar-2026 726 Views

The default access level is available when no access level is specified. All the classes, data members, methods etc. which have the default access level can only be accessed inside the same package.A program that demonstrates the default access level in Java is given as follows:Exampleclass Employee {    int empno;    String name;    void insert(int e, String n) {       empno = e;       name = n;    }    void display() {       System.out.println("Employee Number: " + empno);       System.out.println("Name: " + name);    } } public class Demo ...

Read More

Why do we use import statement in Java? Where it should be included in the class?

Rishi Raj
Rishi Raj
Updated on 11-Mar-2026 5K+ Views

The import statement can be used to import an entire package or sometimes import certain classes and interfaces inside the package. The import statement is written before the class definition and after the package statement(if there is any). Also, the import statement is optional.A program that demonstrates this in Java is given as follows:Exampleimport java.util.LinkedList; public class Demo {    public static void main(String[] args) {       LinkedList l = new LinkedList();       l.add("Apple");       l.add("Mango");       l.add("Cherry");       l.add("Orange");       l.add("Pear");       System.out.println("The LinkedList ...

Read More

C++ Program to Construct an Expression Tree for a Postfix Expression

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

An expression tree is basically a binary tree which is used to represent expressions. In expression tree, nodes correspond to the operator and each leaf node corresponds to the operand. This is a C++ program to construct an expression tree for a postfix Expression in inorder, preorder and postorder traversals.AlgorithmBegin    Function r() has a character variable as parameter.       If the characters are + or - or * or / then          Return will be -1       If the characters are from A to Z then          Return will ...

Read More

How to convert Integer array list to float array in Java?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 1K+ Views

To convert integer array list to float array, let us first create an integer array list −ArrayList < Integer > arrList = new ArrayList < Integer > (); arrList.add(25); arrList.add(50); arrList.add(100); arrList.add(200); arrList.add(300); arrList.add(400); arrList.add(500);Now, convert integer array list to float array. We have first set the size to the float array. With that, each and every value of the integer array is assigned to the float array −final float[] arr = new float[arrList.size()]; int index = 0; for (final Integer value: arrList) {    arr[index++] = value; }Exampleimport java.util.ArrayList; public class Demo {    public static void main(String[] args) ...

Read More

Print a Vector in a comma-delimited list, in index order and surrounded by square brackets ([]) in Java

Arushi
Arushi
Updated on 11-Mar-2026 585 Views

A Vector can be printed in a comma-delimited list, in index order and surrounded by square brackets ([]) by simply using System.out.println() along with the Vector object.A program that demonstrates this is given as follows −Exampleimport java.util.Vector; public class Demo {    public static void main(String args[]) {       Vector vec = new Vector(5);       vec.add(4);       vec.add(1);       vec.add(3);       vec.add(9);       vec.add(6);       System.out.println(vec);    } }The output of the above program is as follows −[4, 1, 3, 9, 6]Now let us understand the ...

Read More

IntStream toArray() method in Java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 299 Views

The toArray() method returns an array containing the elements of this stream.Set the elements in the stream with the IntStream class of() method.IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140);Now, display an array with the elements of this stream using the toArray() method.int[] myArr = stream.toArray();The following is the syntax.int[] toArray()The following is an example to implement IntStream toArray() method in Java.Exampleimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140);       int[] myArr = stream.toArray();       System.out.println(Arrays.toString(myArr));    } }Output[20, 40, 60, 70, 100, 120, 140]

Read More

C++ Program to Find Deepest Left Leaf in a Binary Tree

Samual Sam
Samual Sam
Updated on 11-Mar-2026 264 Views

A binary tree which has at most two children, specified as left child and right child. This is a C++ Program to Find Deepest Left Leaf in a Binary TreeAlgorithmBegin.    function deepestLLeafutil() find the deepest left leaf in a given    binary tree:         lvel is level of current node.       maxlvel is pointer to the deepest left leaf node found so far         isLeft Indicates that this node is left child of its parent         resPtr is Pointer to the result         If root is equal to Null ...

Read More

How to generate random values that won't repeat in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 519 Views

To generate random values that won’t repeat, use HashSet collection. Firstly, create a random object and HashSet −Random randNum = new Random(); Sets = new HashSet();Now, add random integers −while (s.size() < 10) {    s.add(randNum.nextInt()); }Now, display the random numbers that are unique −Listlist = new ArrayList(s); System.out.println(list);Exampleimport java.util.ArrayList; import java.util.HashSet; import java.util.Set; import java.util.Random; import java.util.List; public class Demo {    public static void main(String[] args) {       Random randNum = new Random();       Sets = new HashSet();       while (s.size() < 10) {          s.add(randNum.nextInt());       ...

Read More
Showing 15361–15370 of 25,466 articles
Advertisements