Тести
Мова сайту: Українська
Українська
English
Русский
Тести з програмування
Вхід
Реєстрація
Тести з програмування
Теорія
Сніпети
Статті
Головна
Android
Ціни
FAQ
Історія Cosmo
Правила та умови сервісу
Політика конфіденційності
Політика щодо файлів cookie
Зворотній Зв’язок
Concurrent collections
:
Мова контенту: English
Русский
Java Collections
Concurrent collections
What will the following code's execution print to console? import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; public class Test { private static void removeAndPrint(List<String> list) { for (String str : list) { if (str.equals("two")) { list.remove("three"); } } System.out.println(list); } public static void main(String[] args) { List<String> list = new CopyOnWriteArrayList<String>(); list.add("one"); list.add("two"); list.add("three"); list.add("four"); removeAndPrint(list); } }
Concurrent collections
What is the result of the code? import java.util.*; public class TestIterator{ public static void main(String[] args){ final List synchList = Collections.synchronizedList(new ArrayList()); fillList(synchList, 10); Thread anotherThread = new Thread(){ public void run(){ try{ Thread.sleep(300); }catch (InterruptedException e){ System.out.println("anotherThread interrupted"); return; } synchList.remove(1); synchList.remove(7); } }; anotherThread.start(); Iterator iterator = synchList.iterator(); while(iterator.hasNext()){ System.out.print(iterator.next()); try{ Thread.sleep(100); } catch (InterruptedException e) { System.out.println("Main thread interrupted"); return; } } } static void fillList(List list, int n){ for(int i = 1; i <= n; i++) list.add(i); } }
Concurrent collections
← Попередня
1
Наступна →
Зареєструйся Зараз
або
Підпишись на майбутні тести