Can Java 8 Streams operate on an item in a collection, and then remove it?

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

Java 8 stream map to list of keys sorted by values

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());

Does C# have a way of giving me an immutable Dictionary?

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)