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
sets
:
Content language: English
Русский
Java Collections
sets
What will happen after the following code compilation and execution: class TreeTest { private static Set<String> set = new TreeSet<String>(); public static void main(String[] args) { set.add("one"); set.add("two"); set.add("three"); set.add("/u000a"); set.add("/u000d"); set.add("/u000c"); set.add("1"); set.add("2"); set.add("3"); for (String string : set) { System.out.print(string + " "); } } }
sets
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 + " "); } } }
sets
Which java.util.Set realizations sorts the elements by their natural order (or on Comparator basis).?
sets
What will be the output of the following code? import java.util.*; public class My11 { public static void main(String...args) { final int num = 3; LinkedHashMap<String,String> map = new LinkedHashMap<String,String>(num,1,true) { public boolean removeEldestEntry (Map.Entry<String,String> eldest) { return size()>num; } }; map.put("1", "str1"); map.put("2", "str2"); map.put("3", "str3"); map.put("4", "str4"); map.get("2"); System.out.println(map); } }
sets
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>());
sets
What will be printed after execution of this code? class User { private String name; public User( String name ) { this.name = name; } public boolean equals( Object obj ) { User user = (User) obj; return user.name.equals( name ); } public String toString() { return name; } } class Foo { public static void main(String...arguments) { //1 User user1 = new User( "John" ); User user2 = new User( "Bill" ); User user3 = new User( "John" ); Set<User> userSet = new HashSet<User>(); userSet.add( user1 ); userSet.add( user2 ); userSet.add( user3 ); //2 System.out.println( "Count of users: " + userSet.size() ); //3 } }
sets
What is the result of compilation and execution of the following code: import java.util.*; class Main { public static void main(String[] args) { List<String> list = Arrays.asList("a", "b", "c", "d", "e"); NavigableSet<String> set = new HashSet<String>(list); System.out.println("Less d: " + set.lower("d")); System.out.println("Greater b: " + set.higher("b")); } }
sets
What will be the output of the following code, assuming all imports are in place and the code is inside a main method? NavigableMap<String, String> nm = new TreeMap<String, String>(); nm.put("1", "one"); nm.put("3", "three"); nm.put("2", "two"); nm.put("4", "four"); NavigableSet<String> keys = nm.keySet(); NavigableSet<String> subKeys = keys.subSet("1", true, "3", false); for(String s: subKeys) { System.out.print(s + " "); }
sets
What will be the result of execution of the following code? Set<Integer> numbers = new LinkedHashSet<Integer>(Arrays.asList(1,2,3,4)); for(Integer i : numbers) { if( i % 2 == 0) numbers.remove(i); } System.out.println(numbers);
sets
← Prev
1
2
Next →
Sign Up Now
or
Subscribe for future quizzes