Quizzes
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
collections
:
Content language: English
Русский
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); } }
collections
What will happen after compilation and execution of the following code? import java.util.*; public class Main { public static void main(String[] args) { try { ArrayList<Integer> ar = new ArrayList<Integer>(); List temp = ar; //1 temp.add(new java.util.Date()); //2 temp.add(new Float(1.66)); Iterator it = ar.iterator(); while (it.hasNext()) System.out.println(it.next()); System.out.println(ar.get(0)); } catch (Exception e) { System.out.println(e.getClass()); } } }
collections
Which line in the code below will generate a compilation error? 01. public class Q11 { 02. public static void main(String[] args) { 03. List<? super Integer> one = new ArrayList<Integer>(); 04. addsome((List<? super Number>) one); 05. } 06. private static void addsome (List<? super Number> l){ 07. l.add(1); 08. Number num = 1; 09. l.add(num); 10. Object ob = 1; 11. l.add(ob); 12. l.add(null); 13. } 14. }
collections
Which collection classes from Java library extends AbstractCollection class?
collections
Presuming the method below is in a public class and it's invocations are included in a main method of the same class, what will be printed to the console? public static void test(Collection<Integer> c) { c.add(3); c.add(2); c.add(1); c.add(2); c.remove(3); System.out.println(c); } ... test(new ArrayList<Integer>()); test(new LinkedHashSet<Integer>()); test(new TreeSet<Integer>());
collections
What will be displayed ? public class Tst { public static class Foo { private final Integer x; public Foo(Integer x) { this.x = x; } public boolean equals(Foo f) { return f.x.equals(this.x); } public int hashCode() { return x.intValue(); } } public static void main(String[] args) { final Foo f1 = new Foo(1); final Foo f2 = new Foo(1); final Set<Foo> set = new HashSet<Foo>(); set.add(f1); set.add(f2); System.out.println(set.size()); } }
collections
Select all correct statements:
collections
What is the result of compilation and execution of the following program: import java.util.*; class Main { public static void main(String[] args) { List<?> list = new ArrayList<String>(); list.add("a"); System.out.println(list.get(0)); } }
collections
What is the result of following code execution: class User { public Integer id; public String username; public User(Integer id, String username) { this.id = id; this.username = username; } } public static void main (String[] args) { List<User> userList = new ArrayList<>(); userList.add(new User(1, "admin")); userList.add(new User(2, "guest")); userList.add(new User(3, null)); Map<Integer, String> idsUsernamesMap = userList.stream().collect(Collectors.toMap(user -> user.id, user -> user.username)); idsUsernamesMap.forEach( (k,v) -> System.out.println("id: " + k + "; username: " + v)); }
collections
← Prev
1
2
Next →
Sign Up Now
or
Subscribe for future quizzes