Assert equals between 2 Lists in Junit

How can I make an equality assertion between lists in a JUnit test case? Equality should be between the content of the list. For example: List<String> numbers = Arrays.asList(“one”, “two”, “three”); List<String> numbers2 = Arrays.asList(“one”, “two”, “three”); List<String> numbers3 = Arrays.asList(“one”, “two”, “four”); // numbers should be equal to numbers2 //numbers should not be equal … Read more

count vs length vs size in a collection

From using a number of programming languages and libraries I have noticed various terms used for the total number of elements in a collection. The most common seem to be length, count, and size. eg. array.length vector.size() collection.count Is there any preferred term to be used? Does it depend on what type of collection it … Read more

How can I initialize an ArrayList with all zeroes in Java?

It looks like arraylist is not doing its job for presizing: // presizing ArrayList<Integer> list = new ArrayList<Integer>(60); Afterwards when I try to access it: list.get(5) Instead of returning 0 it throws IndexOutOfBoundsException: Index 5 out of bounds for length 0. Is there a way to initialize all elements to 0 of an exact size … Read more

Immutable vs Unmodifiable collection [duplicate]

This question already has answers here: Java Immutable Collections (7 answers) Closed 2 days ago. From the Collections Framework Overview: Collections that do not support modification operations (such as add, remove and clear) are referred to as unmodifiable. Collections that are not unmodifiable are modifiable. Collections that additionally guarantee that no change in the Collection … Read more

How to sort Counter by value? – python

Other than doing list comprehensions of reversed list comprehension, is there a pythonic way to sort Counter by value? If so, it is faster than this: >>> from collections import Counter >>> x = Counter({‘a’:5, ‘b’:3, ‘c’:7}) >>> sorted(x) [‘a’, ‘b’, ‘c’] >>> sorted(x.items()) [(‘a’, 5), (‘b’, 3), (‘c’, 7)] >>> [(l,k) for k,l in … Read more