Тесты
Язык сайта: Русский
Українська
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
Следующая →
Зарегистрируйся сейчас
или
Подпишись на будущие тесты