- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4337 Articles for Java 8
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
113 Views
With this, get the nanoseconds in days, hours and minutes. At first, set the Duration:Duration d1 = Duration.ofDays(5); Duration d2 = Duration.ofHours(20); Duration d3 = Duration.ofMinutes(15);Convert the above Duration to nanoseconds:System.out.println("Nanoseconds in 5 days = "+d1.toNanos()); System.out.println("Nanoseconds in 20 hours = "+d2.toNanos()); System.out.println("Nanoseconds in 15 minutes = "+d3.toNanos());Exampleimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d1 = Duration.ofDays(5); Duration d2 = Duration.ofHours(20); Duration d3 = Duration.ofMinutes(15); System.out.println("Nanoseconds in 5 days = "+d1.toNanos()); System.out.println("Nanoseconds in 20 hours = "+d2.toNanos()); ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
177 Views
At first, set the Duration:Duration duration = Duration.ofHours(10);Now, get the number of minutes from the above Duration that has 10 hours:d1.toMinutes()Exampleimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d1 = Duration.ofDays(25); Duration d2 = Duration.ofHours(10); System.out.println("Minutes in 25 days = "+d1.toMinutes()); System.out.println("Minutes in 10 hours = "+d2.toMinutes()); } }OutputMinutes in 25 days = 36000 Minutes in 10 hours = 600
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
92 Views
We will get seconds here based on days, hours, millis and minutes, for example, how many seconds in 10 days, seconds in 10 hours, etc.Duration for days, hours, milliseconds and minutes:Duration duration = Duration.ofDays(10); Duration duration1 = Duration.ofHours(10); Duration duration2 = Duration.ofMillis(10); Duration duration3 = Duration.ofMinutes(10);Now, get the seconds:System.out.println("Seconds in 10 days = "+duration.getSeconds()); System.out.println("Seconds in 10 hours = "+duration1.getSeconds()); System.out.println("Seconds in 10 milliseconds = "+duration2.getSeconds()); System.out.println("Seconds in 10 minutes = "+duration3.getSeconds());Exampleimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration duration = Duration.ofDays(10); Duration duration1 = Duration.ofHours(10); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
208 Views
Let’s say the following is our List with elements −ArrayList < String > arrList = new ArrayList < String > (); arrList.add("Jack"); arrList.add("Tom"); arrList.add("Brad"); arrList.add("Amy"); arrList.add("Ben"); arrList.add("Peter"); arrList.add("Katie"); arrList.add("Tim");Now, use the listIterator(). The next() method returns the next element in the List. Hoverer, remove an element using remove() method −ListIteratoriterator = arrList.listIterator(); iterator.next(); iterator.remove();Example Live Demoimport java.util.ArrayList; import java.util.ListIterator; public class Demo { public static void main(String[] args) { ArrayListarrList = new ArrayList(); arrList.add("Jack"); arrList.add("Tom"); arrList.add("Brad"); arrList.add("Amy"); arrList.add("Ben"); arrList.add("Peter"); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
Let’s say your list is having the following elements −P, W, g, K, H, t, ETherefore, case sensitive order means, capital and small letters will be considered irrespective of case. The output would be −E, g, H, K, P, t, WThe following is our array −String[] arr = new String[] { "P", "W", "g", "K", "H", "t", "E" };Convert the above array to a List −Listlist = Arrays.asList(arr);Now sort the above list in case insensitive order −Collections.sort(list, String.CASE_INSENSITIVE_ORDER);Example Live Demoimport java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo { public static void main(String[] argv) throws Exception { ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
368 Views
Let’s say the following is a List. In this, we have duplicates elements as well −Listls = new ArrayList(); ls.add("A"); ls.add("B"); ls.add("C"); ls.add("D"); ls.add("D"); ls.add("E"); ls.add("F"); ls.add("G"); ls.add("E");Now, create a TreeSet and merge the duplicates of the List −TreeSetset = new TreeSet(); set.addAll(ls);Example Live Demoimport java.util.ArrayList; import java.util.TreeSet; import java.util.List; public class Demo { public static void main(String[] args) { Listls = new ArrayList(); ls.add("A"); ls.add("B"); ls.add("C"); ls.add("D"); ls.add("D"); ls.add("E"); ls.add("F"); ls.add("G"); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
660 Views
To fill multiple copies of specified object to a list means let’s say you have an element 100 and want to display it 10 times. For this, let us see an example.The following is our list and iterator. We have used nCopiec Collections method to set the elements and how many copies you want −Listlist = Collections.nCopies(10, 100); Iteratoriterator = list.iterator();After that display the multiple copies −while (iterator.hasNext()) System.out.println(iterator.next());Example Live Demoimport java.util.Collections; import java.util.Iterator; import java.util.List; public class Demo { public static void main(String[] args) { Listlist = Collections.nCopies(10, 100); Iteratoriterator = list.iterator(); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
592 Views
Let’s say your list is having the following elements −P, W, g, K, H, t, ETherefore, case sensitive order means, at first the sorted order would be in capital letters and then small −E, H, K, P, W, g, tThe following is our array −String[] arr = new String[] { "P", "W", "g", "K", "H", "t", "E" };Convert the above array to a List −Listlist = Arrays.asList(arr);Now sort the above list in case sensitive order −Collections.sort(list);Exampleimport java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo { public static void main(String[] arg v) throwsException { String[] arr = ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
In this article, we will learn how to convert a local date to a java.util.Date in UTC using Java's date and time API. Problem Statement Convert the current date, to a java.util.Date object in Coordinated Universal Time (UTC). The goal is to achieve this conversion while ensuring that the resulting java.util.Date object represents the start of the day in UTC for the given LocalDate. Steps to Convert LocalDate to java.util.Date in UTC The following are the steps to convert LocalDate to java.util.Date in UTC Step 1: Import the required classes i.e., java.time and java.util ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
125 Views
Set the LocalDate to now −LocalDate date = LocalDate.now();Now, set the TimeZone offset −ZoneOffset timeZone = ZoneOffset.UTC;Convert the LocalDate to java.util.Date −Date.from(date.atStartOfDay().toInstant(timeZone))Example Live Demoimport java.time.LocalDate; import java.time.ZoneOffset; import java.util.Date; public class Demo { public static void main(String[] args) { LocalDate date = LocalDate.now(); System.out.println("Date = "+date); ZoneOffset timeZone = ZoneOffset.UTC; System.out.println(Date.from(date.atStartOfDay().toInstant(timeZone))); } }OutputDate = 2019-04-19 Fri Apr 19 05:30:00 IST 2019