Convert Milliseconds to Date Format in Java

AmitDiwan
Updated on 23-Sep-2019 13:55:13

1K+ Views

Let us first declare and initialize milliseconds value variable −long milliSeconds = 656478;Now, convert Milliseconds to Date format −DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss:SSS Z"); Date date = new Date(milliSeconds);Following is the program to convert Milliseconds to Date Format in Java −Exampleimport java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Demo {    public static void main(String args[]) {       long milliSeconds = 656478;       DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss:SSS Z");       Date date = new Date(milliSeconds);       System.out.println(dateFormat.format(date));    } }Output01 Jan 1970 00:10:56:478 +0000

Convert List to Stream in Java

AmitDiwan
Updated on 23-Sep-2019 12:59:23

840 Views

Here’s our List with string values −List myList = Arrays.asList("One", "Two", "Three", "Four", "Five");Now, let us convert this List to Stream −Stream s = myList.stream();Following is the program to convert List to Stream in Java −Exampleimport java.util.*; import java.util.stream.*; import java.util.function.Function; public class Demo {    public static void main(String args[]) {       List myList = Arrays.asList("One", "Two", "Three", "Four", "Five");       System.out.println("List: " + myList);       Stream s = myList.stream();       System.out.println("Stream (List to Stream) = " + Arrays.toString(s.toArray()));    } }OutputList: [One, Two, Three, Four, Five] Stream (List to Stream) ... Read More

Convert List of String to List of Integer in Java

AmitDiwan
Updated on 23-Sep-2019 12:58:22

1K+ Views

Here’s our List of String −List listString = Arrays.asList("25", "50", "75", "100", "125", "150");Now, convert the list of string to list of integer −List listInteger = listString.stream().map(Integer::parseInt).collect(Collectors.toList());Following is the program to convert List of String to List of Integer in Java −Exampleimport java.util.*; import java.util.stream.*; import java.util.function.*; public class Demo {    public static void main(String[] args) {       List listString = Arrays.asList("25", "50", "75", "100", "125", "150");       System.out.println("List of String = " + listString);       List listInteger = listString.stream().map(Integer::parseInt)          .collect(Collectors.toList());       System.out.println("List of Integer (converted from ... Read More

Convert List of Integer to List of String in Java

AmitDiwan
Updated on 23-Sep-2019 12:56:52

778 Views

Here’s our List of Integer −List listInteger = Arrays.asList(25, 50, 75, 100, 125, 150);Now, convert List of Integer to List of String −List listString = listInteger.stream()    .map(s -> String.valueOf(s))    .collect(Collectors.toList());Following is the program to convert List of Integer to List of String in Java −Exampleimport java.util.*; import java.util.stream.*; import java.util.function.*; public class Demo {    public static void main(String[] args) {       List listInteger = Arrays.asList(25, 50, 75, 100, 125, 150);       System.out.println("List of Integer = " + listInteger);       List listString = listInteger.stream()          .map(s -> String.valueOf(s))   ... Read More

ints.contains() Function in Java

AmitDiwan
Updated on 23-Sep-2019 12:54:46

4K+ Views

The contains() function of the Ints class is used to check whether an element is present in the array or not.Following is the syntax −public static boolean contains(int[] arr, int target)Here, arr is the array wherein the element is to be checked. The target is the element to be checked.Following is an example to implement the contains() method of the Ints class −Exampleimport com.google.common.primitives.Ints; import java.util.*; class Demo {    public static void main(String[] args) {       int[] myArr1 = { 100, 150, 230, 300, 400 };       int[] myArr2 = { 450, 550, 700, 800, ... Read More

Int's concat Function in Java

AmitDiwan
Updated on 23-Sep-2019 12:52:54

210 Views

The concat() function in Ints class is used to concatenate the arrays passed as parameter. The syntax is as follows −public static int[] concat(int[]... arr)Here, parameter arr is zero or more integer arrays.Let us see an example −Exampleimport com.google.common.primitives.Ints; import java.util.*; class Demo {    public static void main(String[] args) {       int[] myArr1 = { 100, 150, 230, 300, 400 };       int[] myArr2 = { 450, 550, 700, 800, 1000 };       System.out.println("Array 1 = ");       for(int i=0; i < myArr1.length; i++) {          System.out.println(myArr1[i]);   ... Read More

Ints.asList() Function in Java

AmitDiwan
Updated on 23-Sep-2019 12:50:56

223 Views

The asList() method of the Ints class in Java Guava’s returns a fixed-size list backed by the specified array. The syntax is as follows −public static List    asList(int[] arr)Here, arr is the array to back the list.Let us see an example to implement the asList() method of the Ints class −Exampleimport com.google.common.primitives.Ints; import java.util.List; class Demo {    public static void main(String[] args) {       int arr[] = { 20, 30, 40, 60, 80, 90, 120, 150 };       System.out.println("Array elements = ");       for(int i = 0; i < arr.length; i++) { ... Read More

Java Integer toHexString Method with Examples

AmitDiwan
Updated on 23-Sep-2019 12:48:42

167 Views

The java.lang.Integer.toHexString() method returns a string representation of the integer argument as an unsigned integer in base 16.Let us now see an example −Exampleimport java.lang.*; public class Main {    public static void main(String[] args) {       int i = 160;       System.out.println("Number = " + i);       System.out.println("Hex = " + Integer.toHexString(i));    } }OutputNumber = 160 Hex = a0ExampleLet us now see another example for negative number −import java.lang.*; public class Main {    public static void main(String[] args) {       int i = -160;       System.out.println("Number = " + i);       System.out.println("Hex = " + Integer.toHexString(i));    } }OutputNumber = -160 Hex = ffffff60

Java Signum Method with Examples

AmitDiwan
Updated on 23-Sep-2019 12:46:47

188 Views

The java.lang.Math.signum(float f) returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.Let us now see an example −Exampleimport java.security.*; import java.util.*; public class Main {    public static void main(String[] argv) {       // get two float numbers       float x = 50.14f;       float y = -4f;       // call signum for both floats and print the result       System.out.println("Math.signum(" + x + ")=" + Math.signum(x));       ... Read More

Java Signature toString Method with Examples

AmitDiwan
Updated on 23-Sep-2019 12:42:17

178 Views

The string representation for the signature object can be obtained using the method getString() in the class java.security.Signature. This includes information such as the object state, algorithm name etcLet us now see an example −Exampleimport java.security.*; import java.util.*; public class Main {    public static void main(String[] argv) {       try {          Signature signature = Signature.getInstance("SHA256withRSA");          String str = signature.toString();          System.out.println(str);       } catch (NoSuchAlgorithmException e) {          System.out.println("Error!!! NoSuchAlgorithmException");       }    } }OutputSignature object: SHA256withRSALet us now ... Read More

Advertisements