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
lists
:
Content language: English
Русский
Java Collections
lists
What will be printed after the following code execution? import java.util.*; public class MapTest { public static void main( String[] args ) { Map<String, Integer> map1 = new HashMap<String, Integer>(); Map<String, Integer> map2 = new HashMap<String, Integer>(); map1.put( "Number1", new Integer( 100 ) ); map1.put( "Number2", new Integer( 200 ) ); map1.put( "Number3", new Integer( 300 ) ); List<Map> list = new ArrayList<Map>(); list.add( map1 ); list.add( map2 ); HashMap resultMap = (HashMap) list.get( 0 ); System.out.println( "Number: " + resultMap.get( "Number2" ) ); } }
lists
What will be the following code execution result? class HashTest { private static Set<String> set = new LinkedHashSet<String>(); public static void main(String[] args) { set.add("one"); set.add("two"); set.add("three"); set.add("two"); for (String string : set) { System.out.print(string + " "); } } }
lists
What will be printed out to console after the following class is compiled and executed: public class A { public static void main(String[] args) { List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(0); Integer[] array = null; list.toArray(array); System.out.println(list.get(1)); } }
lists
What will be the result of compiling and running the following program? import java.util.ArrayList; import java.util.List; public class Test { public static void main(String a[]) { List<Integer> list = new ArrayList<Integer>(); list.add(null); for (Integer i : list) { System.out.println(i); } } }
lists
What will be the result of compiling and running the following code: import java.util.List; import java.util.ArrayList; public class Test { public static void main(String[] args) { List<String> values = new ArrayList<String>() { { add("one"); add("two"); add("three"); } }; System.out.print("values: "); for (String value : values) { System.out.print(value + " "); } } }
lists
What happens when you'll try to compile and run this code: import java.util.*; public class Clazz { public static void main(String[] args) { List arrayList = new ArrayList(); arrayList.add("str1"); arrayList.add("str2"); arrayList.add("str3"); for (int i = 0; i < arrayList.size(); i++) arrayList.remove(i); System.out.println(arrayList.size()); } }
lists
What will be the result of the following code: import java.util.*; public class Test { public static void main(String[] args) { Class c1 = new ArrayList<String>().getClass(); Class c2 = new ArrayList<Integer>().getClass(); System.out.println(c1 == c2); } }
lists
What will be the result of the code: import java.util.Arrays; import java.util.Iterator; import java.util.List; public class Test { public static void main(String[] args) { String[] str = new String[] { "1", "2", "3" }; List list = Arrays.asList(str); for (Iterator iterator = list.iterator(); iterator.hasNext();) { Object object = (Object) iterator.next(); iterator.remove(); } System.out.println(list.size()); } }
lists
What happens if you run this code: class Test { List<Integer> list; Test(){ list = new ArrayList<Integer>(); someVoid(list); } void someVoid(List<Integer> l){ l.add(0); l=null; } public static void main(String[] args) { Test test=new Test(); System.out.println("Size is: "+test.list.size()); } }
lists
← Prev
1
2
3
Next →
Sign Up Now
or
Subscribe for future quizzes