Java lang Long.toOctalString() Method with Examples

AmitDiwan
Updated on 24-Sep-2019 08:08:47

61 Views

The java.lang.Long.toOctalString() method returns a string representation of the long argument as an unsigned integer in base 8.ExampleLet us now see an example −import java.lang.*; public class Main {    public static void main(String[] args) {       long l = 220;       System.out.println("Number = " + l);       /* returns the string representation of the unsigned long value       represented by the argument in Octal (base 8) */       System.out.println("Octal = " + Long.toOctalString(l));    } }OutputNumber = 220 Octal = 334ExampleLet us now see another example wherein negative number ... Read More

Mathematical Functions in Java

AmitDiwan
Updated on 24-Sep-2019 08:03:53

2K+ Views

The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. This class provides mathematical functions in Java.Let us see some of these functions −Sr.NoMethod & Description1static double abs(double a)This method returns the absolute value of a double value.2static float abs(float a)This method returns the absolute value of a float value.3static int abs(int a)This method returns the absolute value of an int value.4static long abs(long a)This method returns the absolute value of a long value.5static double acos(double a)This method returns the arc cosine of a value; the returned angle is ... Read More

Random Numbers in Java

AmitDiwan
Updated on 24-Sep-2019 08:01:26

200 Views

The java.util.Random class instance is used to generate a stream of pseudorandom numbers. Following are the methods provided by the Random class to set the seed of the random number, generate the next random number.Let us learn about some of these methods −Sr.NoMethod & Description1protected int next(int bits)This method generates the next pseudorandom number.2boolean nextBoolean()This method returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.3void nextBytes(byte[] bytes)This method generates random bytes and places them into a user-supplied byte array.4double nextDouble()This method returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number ... Read More

Calendar Functions in Java

AmitDiwan
Updated on 24-Sep-2019 07:57:43

974 Views

The java.util.calendar class provides the calendar functions in Java. Is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week.Following are the calendar functions in Java −Sr.NoMethod & Description1abstract void add(int field, int amount)This method adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.2boolean after(Object when)This method returns whether this Calendar represents a time after the time ... Read More

Iterator Functions in Java

AmitDiwan
Updated on 24-Sep-2019 07:50:30

974 Views

Iterator in Java is used to traverse each and every element in the collection. Using it, traverse, obtain each element or you can even remove. ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.Following are the Interator Functions in Java −Modifier and TypeMethod & Descriptiondefault voidforEachRemaining(Consumer

Dictionary Methods in Java

AmitDiwan
Updated on 24-Sep-2019 07:47:44

1K+ Views

Dictionary is an abstract class that represents a key/value storage repository and operates much like Map. Given a key and value, you can store the value in a Dictionary object. Once the value is stored, you can retrieve it by using its key. Thus, like a map, a dictionary can be thought of as a list of key/value pairs.Following are the methods defined by Dictionary are listed below −Sr.NoMethod & Description1Enumeration elements( )Returns an enumeration of the values contained in the dictionary.2Object get(Object key)Returns the object that contains the value associated with the key. If the key is not in ... Read More

Ints toArray() function in Java

AmitDiwan
Updated on 24-Sep-2019 07:41:09

188 Views

The toArray() method of the Ints class returns an array containing each value of collection, converted to a int value in the manner of Number.intValue(). Following is the syntax −public static int[]    toArray(Collection

Ints max() function in Java

AmitDiwan
Updated on 24-Sep-2019 07:39:45

104 Views

The max() method of the Ints class returns the greatest value present in array. Following is the syntax −static int max(int... array)Let us first see an example −Exampleimport com.google.common.primitives.Ints; class Demo {    public static void main(String[] args) {       int[] myArr = { 10, 20, 30, 40, 50, 60, 20, 80, 20, 100 };       System.out.println(Ints.join("-", myArr));       System.out.println("Maximum value from the array = " + Ints.max(myArr));       // finding last index of element 20       int index = Ints.lastIndexOf(myArr, 20);       if (index != -1) { ... Read More

Ints lastIndexOf() function in Java

AmitDiwan
Updated on 24-Sep-2019 07:37:08

71 Views

The lastIndexOf() method of the Ints class returns the index of the last appearance of the value target in array. The syntax is as follows −public static int lastIndexOf(int[] arr, int target)Here, arr is the array of int values, whereas target is the int value for which we are finding the last index.Let us first see an example −Exampleimport com.google.common.primitives.Ints; class Demo {    public static void main(String[] args) {       int[] myArr = { 10, 20, 30, 40, 50, 60, 20, 80, 20, 100 };       System.out.println(Ints.join("-", myArr));       // finding last index ... Read More

Implement Quintet Class with Quartet Class in Java using JavaTuples

AmitDiwan
Updated on 24-Sep-2019 07:28:39

51 Views

Following is an example to implement Quintet class from Quartet class in Java −Exampleimport org.javatuples.Quartet; import org.javatuples.Quintet; public class MyDemo {    public static void main(String[] args) {       Quartetquartet = new Quartet(          "Table", "Chair", "Pen", "Paper");       System.out.println("Quartet elements = " + quartet);       Quintetquintet = quartet.add("Notebook");       System.out.println("Quintet (implemented from Quartet) elements = " + quintet);    } }OutputQuartet elements = [Table, Chair, Pen, Paper] Quintet (implemented from Quartet) elements = [Table, Chair, Pen, Paper, Notebook]Let us now see another example to implement Quintet class from ... Read More

Advertisements