Samual Sam has Published 2310 Articles

Ternary Operator in Java

Samual Sam

Samual Sam

Updated on 25-Jun-2020 11:14:54

2K+ Views

A ternary operator uses 3 operands and it can be used to replace the if else statement. This can be done to make the code simpler and more compact.The syntax of the ternary operator is given as follows −Expression ? Statement 1 : Statement 2In the above syntax, the expression ... Read More

Set a bit for BigInteger in Java

Samual Sam

Samual Sam

Updated on 25-Jun-2020 11:07:41

211 Views

The setBit() method is used in Java to return a BigInteger whose value is equivalent to this BigInteger with the designated bit set.Example Live Demoimport java.math.*; public class BigIntegerDemo {    public static void main(String[] args) {       BigInteger one, two;       one = new BigInteger("7");   ... Read More

Java Program to flip a bit in a BigInteger

Samual Sam

Samual Sam

Updated on 25-Jun-2020 11:02:24

184 Views

To flip a bit in a BigInteger in Java, use the flipBit() method. This method returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped.Example Live Demoimport java.math.*; public class Demo {    public static void main(String[] args) {       BigInteger one, two;   ... Read More

Shift left in a BigInteger in Java

Samual Sam

Samual Sam

Updated on 25-Jun-2020 10:59:45

193 Views

To shift left in a BigInteger, use the shiftLeft() method.The java.math.BigInteger.shiftLeft(int n) returns a BigInteger whose value is (this

Create a queue using LinkedList class in Java

Samual Sam

Samual Sam

Updated on 25-Jun-2020 10:40:41

274 Views

To create a queue using LinkedList class, try the following −Queue q = new LinkedList(); q.offer("abc"); q.offer("def"); q.offer("ghi"); q.offer("jkl"); q.offer("mno"); q.offer("pqr"); q.offer("stu"); q.offer("vwx");After that to print the elements, you need to use check a condition for Queue as shown below −Object ob; while ((ob = q.poll()) != null) {   ... Read More

Replace an element of a Java LinkedList

Samual Sam

Samual Sam

Updated on 25-Jun-2020 10:37:47

2K+ Views

An element in an Java LinkedList can be replaced using the java.util.ArrayList.set() method. This method has two parameters i.e the index at which the LinkedList element is to be replaced and the element that it should be replaced with. ArrayList.set() method returns the element that was at the position specified ... Read More

Remove an element from a Queue in Java

Samual Sam

Samual Sam

Updated on 25-Jun-2020 10:35:55

3K+ Views

To remove an element from a Queue, use the remove() method.First, set a Queue and insert some elements −Queue q = new LinkedList(); q.offer("abc"); q.offer("def"); q.offer("ghi"); q.offer("jkl"); q.offer("mno"); q.offer("pqr"); q.offer("stu"); q.offer("vwx");Remove the first element −System.out.println("Queue head = " + q.element()); System.out.println("Removing element from queue = " + q.remove());The following is ... Read More

Get the last element from a Sorted Set in Java

Samual Sam

Samual Sam

Updated on 25-Jun-2020 10:33:48

2K+ Views

To create a Sorted Set, firstly create a Set −Set s = new HashSet();Add elements to the above set −int a[] = {77, 23, 4, 66, 99, 112, 45, 56, 39, 89}; Set s = new HashSet(); try {    for(int i = 0; i < 5; i++) {   ... Read More

Check whether a Stack is empty or not in Java

Samual Sam

Samual Sam

Updated on 25-Jun-2020 10:30:57

4K+ Views

The method java.util.Stack.empty() is used to check if a stack is empty or not. This method requires no parameters. It returns true if the stack is empty and false if the stack is not empty.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Stack; public class Demo { ... Read More

DataView.getInt8() function in JavaScript

Samual Sam

Samual Sam

Updated on 25-Jun-2020 10:28:09

63 Views

The getInt8() function of the DataView gets and returns a signed 8-bit floating point number at the specified position.SyntaxIts syntax is as followsdataView.getInt8();Example Live Demo    JavaScript Example           var arrayBuffer = new ArrayBuffer(20);       var dataView = new DataView(arrayBuffer);     ... Read More

Advertisements