make ArrayList Read only
Pass the ArrayList into Collections.unmodifiableList(). It returns an unmodifiable view of the specified list. Only use this returned List, and never the original ArrayList.
Pass the ArrayList into Collections.unmodifiableList(). It returns an unmodifiable view of the specified list. Only use this returned List, and never the original ArrayList.
Isn’t it good enough? Public Function Contains(col As Collection, key As Variant) As Boolean Dim obj As Variant On Error GoTo err Contains = True obj = col(key) Exit Function err: Contains = False End Function
Collections.sort(listToSort, String.CASE_INSENSITIVE_ORDER);
You can do it like this: set.removeIf(item -> { if (!item.qualify()) return false; item.operate(); return true; }); If item.operate() always returns true you can do it very succinctly. set.removeIf(item -> item.qualify() && item.operate()); However, I don’t like these approaches as it is not immediately clear what is going on. Personally, I would continue to use … Read more
Close. Use db.originalCollectionName.renameCollection(‘newCollectionName’) See http://www.mongodb.org/display/DOCS/renameCollection+Command
This should do it if memory serves: List<MyType> fixed = Arrays.asList(new MyType[100]);
You say you want to sort by value, but you don’t have that in your code. Pass a lambda (or method reference) to sorted to tell it how you want to sort. And you want to get the keys; use map to transform entries to keys. List<Type> types = countByType.entrySet().stream() .sorted(Comparator.comparing(Map.Entry::getValue)) .map(Map.Entry::getKey) .collect(Collectors.toList());
No, but a wrapper is rather trivial: public class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue> { IDictionary<TKey, TValue> _dict; public ReadOnlyDictionary(IDictionary<TKey, TValue> backingDict) { _dict = backingDict; } public void Add(TKey key, TValue value) { throw new InvalidOperationException(); } public bool ContainsKey(TKey key) { return _dict.ContainsKey(key); } public ICollection<TKey> Keys { get { return _dict.Keys; } … Read more
Here’s an alternate way foreach ( var s in MyCollection.Where(kv => kv.Value.Member == foo).ToList() ) { MyCollection.Remove(s.Key); } Pushing the code into a list directly allows you to avoid the “removing while enumerating” problem. The .ToList() will force the enumeration before the foreach really starts.
List<Integer> c = new ArrayList<>(a); c.removeAll(b); Also consider to use Sets instead of Lists.