Found 4335 Articles for Java 8

Get the default Time Zone in Java

Chandu yadav
Updated on 26-Jun-2020 09:13:13

2K+ Views

In order to get the default Time Zone in Java, we use the getDefault() method. The java.util.TimeZone.getDefault() method returns the default TimeZone for the particular host. The source of the default TimeZone varies with the implementation.Declaration −The java.util.TimeZone.getDefault() method is declared as follows −public static TimeZone getDefault()Let us see a program to get the default time zone in Java −Example Live Demoimport java.util.*; public class Example {    public static void main( String args[] ) {       // creating default object of TimeZone       TimeZone obj = TimeZone.getDefault();       System.out.println("Default timezone object: " + obj); ... Read More

Get the IDs according to the given time zone offset in Java

George John
Updated on 26-Jun-2020 09:14:08

179 Views

In order to get the IDs according to the given time zone offset in Java, we use the getAvailableIDs(int rawOffset) method. The java.util.TimeZone.getAvailableIDs(int rawOffset) method returns the available IDs according to the given time zone offset in the arguments.Declaration − The java.util.TimeZone.getAvailableIDs(int rawOffset) method is declared as follows −public static String[] getAvailableIDs(int rawOffset)where rawOffset is the given time zone GMT offset.Let us see a Java program which gets the IDs according to the given time zone offset −Example Live Demoimport java.util.*; public class Example {    public static void main(String args[]) {       // getting available supported ids for ... Read More

Get all the IDs of the Time Zone in Java

Chandu yadav
Updated on 26-Jun-2020 09:15:09

5K+ Views

To get all the IDs of the TimeZone in Java, we use the getAvailableIDs() method. The getAvailableIDs() method returns all the available IDs which are compatible.Declaration −The java.util.TimeZone.getAvailableIDs() method is declared as follows −public static String[] getAvailableIDs()Let us see a Java program which gets all the IDs of the Time Zone:Example Live Demoimport java.util.*; public class Example {    public static void main(String args[]) {       // getting available supported ids       String[] id = TimeZone.getAvailableIDs();       // printing available ids       System.out.println("The available IDs are as follows:");       for (int ... Read More

Find maximum element of ArrayList with Java Collections

Arjun Thakur
Updated on 26-Jun-2020 09:16:38

12K+ Views

In order to compute maximum element of ArrayList with Java Collections, we use the Collections.max() method. The java.util.Collections.max() returns the maximum element of the given collection. All elements must be mutually comparable and implement the comparable interface. They shouldn’t throw a ClassCastException.Declaration −The Collections.max() method is declared as follows −public static T max(Collection c)where c is the collection object whose maximum is to be found.Let us see a program to find the maximum element of ArrayList with Java collections −Example Live Demoimport java.util.*; public class Example {    public static void main (String[] args) {       List list ... Read More

Create a copy of a TimeZone object in Java

Ankith Reddy
Updated on 26-Jun-2020 09:17:25

60 Views

In order to get a copy of a TimeZone object in Java, we use the clone() method. The clone() method creates of a copy of the TimeZone.Declaration −The java.util.TimeZone.clone() method is declared as follows −public Object clone()Let us see a Java program which creates a copy of the TimeZone object using the clone() method −Example Live Demoimport java.util.*; public class Example {    public static void main( String args[] ) {       // creating object of TimeZone       TimeZone obj = TimeZone.getDefault();       System.out.println("Initial object: " + obj);       // copying the TimeZone ... Read More

Generate Random boolean in Java

George John
Updated on 29-Jun-2020 06:14:19

12K+ Views

In order to generate Random boolean in Java, we use the nextBoolean() method of the java.util.Random class. This returns the next random boolean value from the random generator sequence.Declaration −The java.util.Random.nextBoolean() method is declared as follows −public boolean nextBoolean()Let us see a program to generate random boolean in Java −Example Live Demoimport java.util.Random; public class Example {    public static void main(String[] args) {       Random rd = new Random(); // creating Random object       System.out.println(rd.nextBoolean()); // displaying a random boolean    } }OutputtrueNote − The output might vary on Online Compilers.

Get elapsed time in days in Java

Ankith Reddy
Updated on 26-Jun-2020 09:22:48

210 Views

To get the elapsed time of an operation in days in Java, we use the System.currentTimeMillis() method. The java.lang.System.currentTimeMillis() returns the current time in milliseconds.Declaration −The java.lang.System.currentTimeMillis() is declared as follows −public static long currentTimeMillis()The method returns time difference in milliseconds between the current time and midnight, January 1, 1970 (UTC or epoch time).Let us see a program to compute the elapsed time of an operation in days in Java −Example Live Demopublic class Example {    public static void main(String[] args) throws Exception {       // finding the time before the operation is executed       long ... Read More

Compute elapsed time in hours in Java

Arjun Thakur
Updated on 26-Jun-2020 09:23:47

372 Views

To get the elapsed time of an operation in hours in Java, we use the System.currentTimeMillis() method. The java.lang.System.currentTimeMillis() returns the current time in milliseconds.Declaration −The java.lang.System.currentTimeMillis() is declared as follows −public static long currentTimeMillis()The method returns time difference in milliseconds between the current time and midnight, January 1, 1970 (UTC or epoch time).Let us see a program to compute the elapsed time of an operation in hours in Java −Example Live Demopublic class Example {    public static void main(String[] args) throws Exception {       // finding the time before the operation is executed       long ... Read More

Get elapsed time in minutes in Java

Chandu yadav
Updated on 26-Jun-2020 09:25:07

2K+ Views

To get the elapsed time of an operation in minutes in Java, we use the System.currentTimeMillis() method. The java.lang.System.currentTimeMillis() returns the current time in milliseconds.Declaration −The java.lang.System.currentTimeMillis() is declared as follows −public static long currentTimeMillis()The method returns time difference in milliseconds between the current time and midnight, January 1, 1970 (UTC or epoch time).Let us see a program to compute the elapsed time of an operation in minutes in Java −Example Live Demopublic class Example {    public static void main(String[] args) throws Exception {       // finding the time before the operation is executed       long ... Read More

Compute the elapsed time of an operation in Java

George John
Updated on 26-Jun-2020 09:28:08

165 Views

To compute the elapsed time of an operation in Java, we use the System.currentTimeMillis() method. The java.lang.System.currentTimeMillis() returns the current time in milliseconds.Declaration −The java.lang.System.currentTimeMillis() is declared as follows −public static long currentTimeMillis()The method returns time difference in milliseconds between the current time and midnight, January 1, 1970 (UTC or epoch time).Let us see a program to compute the elapsed time of an operation in Java −Example Live Demopublic class Example {    public static void main(String[] args) throws Exception {       // finding the time before the operation is executed       long start = System.currentTimeMillis();   ... Read More

Advertisements