Listlist = new ArrayList (); // add some items to the list list.add("item1"); list.add("item2"); list.add("item3"); synchronized(list) { // wait for another thread to notify this thread list.wait(); }
ListIn this example, a List of integers is created and some items are added to it. The list is then synchronized, and the thread waits for 5 seconds until another thread notifies it to continue. The List interface is a part of the Java Collections Framework, which is a package library that provides a set of interfaces, classes and algorithms for handling collections of objects. The java.util package is a part of the Java Standard Library and contains classes and interfaces for various collections, such as lists, sets, and maps, among others.list = new LinkedList (); // add some items to the list list.add(1); list.add(2); list.add(3); synchronized(list) { // wait for another thread to notify this thread for specified time list.wait(5000); }