Tutorialspoint

Java toString() method of CopyOnWriteArrayList

import java.util.concurrent.CopyOnWriteArrayList;
public class Demo {
   public static void main(String[] args) {
      CopyOnWriteArrayList < Integer > arrList = new CopyOnWriteArrayList < Integer > ();
      arrList.add(100);
      arrList.add(250);
      arrList.add(0, 400);
      arrList.add(1, 500);
      arrList.add(2, 650);
      arrList.add(700);
      arrList.add(800);
      System.out.println("CopyOnWriteArrayList String Representation = " + arrList.toString());
   }
}  

Java Insert the specified element at the specified position

import java.util.concurrent.CopyOnWriteArrayList;
public class Demo {
   public static void main(String[] args) {
      CopyOnWriteArrayList < Integer > arrList = new CopyOnWriteArrayList < Integer > ();
      arrList.add(100);
      arrList.add(250);
      arrList.add(0, 400);
      arrList.add(1, 500);
      arrList.add(2, 650);
      arrList.add(700);
      arrList.add(800);
      System.out.println("CopyOnWriteArrayList Elements = " + arrList);
       
   }
}

Java add(int index, E element) method

import java.util.concurrent.CopyOnWriteArrayList;
public class Demo {
   public static void main(String[] args) {
      CopyOnWriteArrayList < Integer > arrList = new CopyOnWriteArrayList < Integer > ();
      arrList.add(100);
      arrList.add(250);
      arrList.add(0, 400);
      arrList.add(1, 500);
      arrList.add(2, 650);
      arrList.add(700);
      arrList.add(800);
      System.out.println("CopyOnWriteArrayList Elements = " + arrList);
   }
}

LocalTime query() Method in Java

import java.time.*;
import java.time.temporal.*;
public class Demo {
	public static void main(String[] args) {
		LocalTime lt = LocalTime.parse("23:15:30");
		System.out.println("The LocalTime is: " + lt);
		String precision = lt.query(TemporalQueries.precision()).toString();
		System.out.println("The Precision for the LocalTime is: "+ precision);
	}
}

Duration toNanos() method in Java

import java.time.Duration;
public class Demo {
	public static void main(String[] args) {
		Duration d = Duration.ofSeconds(1);
		System.out.println("The duration is: " + d);
		System.out.println("The number of nanoseconds in the duration is: " + d.toNanos());
	}
}

Duration toMillis() method in Java

import java.time.Duration;
public class Demo {
	public static void main(String[] args) {
		Duration d = Duration.ofSeconds(1);
		System.out.println("The duration is: " + d);
		System.out.println("The number of milliseconds in the duration is: " + d.toMillis());
	}
}

Duration plus() method in Java

import java.time.Duration;
public class Demo {
	public static void main(String[] args) {
		Duration d1 = Duration.ofHours(2);
		Duration d2 = Duration.ofHours(6);
		System.out.println("The first duration is: " + d1);
		System.out.println("The second duration is: " + d2);
		System.out.println("The duration obtained when the second duration is added to the first duration is: " + d1.plus(d2));
	}
}

Java add(E e) method

import java.util.concurrent.CopyOnWriteArrayList;
public class Demo {
   public static void main(String[] args) {
      CopyOnWriteArrayList < Integer > arrList = new CopyOnWriteArrayList < Integer > ();
      arrList.add(100);
      arrList.add(250);
      arrList.add(400);
      arrList.add(500);
      arrList.add(650);
      arrList.add(700);
      arrList.add(800);
      System.out.println("CopyOnWriteArrayList Elements = " + arrList);
      System.out.println("The element at 2nd position = " + arrList.get(1));
      System.out.println("Does the element exist in the List? = " + arrList.contains(400));
   }
}

Duration minusDays() method in Java

import java.time.Duration;
public class Demo {
	public static void main(String[] args) {
		Duration d = Duration.ofDays(5);
		System.out.println("The duration is: " + d);
		System.out.println("A copy with 2 days removed from the duration is: " + d.minusDays(2));
	}
}

Duration minusHours() method in Java

import java.time.Duration;
public class Demo {
	public static void main(String[] args) {
		Duration d = Duration.ofHours(6);
		System.out.println("The duration is: " + d);
		System.out.println("A copy with 4 hours removed from the duration is: " + d.minusHours(4));
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.