How to convert List to Map?

With java-8, you’ll be able to do this in one line using streams, and the Collectors class. Map<String, Item> map = list.stream().collect(Collectors.toMap(Item::getKey, item -> item)); Short demo: import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class Test{ public static void main (String [] args){ List<Item> list = IntStream.rangeClosed(1, 4) .mapToObj(Item::new) .collect(Collectors.toList()); //[Item [i=1], Item … Read more

Tree data structure in C#

My best advice would be that there is no standard tree data structure because there are so many ways you could implement it that it would be impossible to cover all bases with one solution. The more specific a solution, the less likely it is applicable to any given problem. I even get annoyed with … Read more

Does VBA have Dictionary Structure?

Yes. Set a reference to MS Scripting runtime (‘Microsoft Scripting Runtime’). As per @regjo’s comment, go to Tools->References and tick the box for ‘Microsoft Scripting Runtime’. Create a dictionary instance using the code below: Set dict = CreateObject(“Scripting.Dictionary”) or Dim dict As New Scripting.Dictionary Example of use: If Not dict.Exists(key) Then dict.Add key, value End … Read more

How can I implement a tree in Python?

I recommend anytree (I am the author). Example: from anytree import Node, RenderTree udo = Node(“Udo”) marc = Node(“Marc”, parent=udo) lian = Node(“Lian”, parent=marc) dan = Node(“Dan”, parent=udo) jet = Node(“Jet”, parent=dan) jan = Node(“Jan”, parent=dan) joe = Node(“Joe”, parent=dan) print(udo) Node(‘/Udo’) print(joe) Node(‘/Udo/Dan/Joe’) for pre, fill, node in RenderTree(udo): print(“%s%s” % (pre, node.name)) Udo … Read more

What is C# analog of C++ std::pair?

Tuples are available since .NET4.0 and support generics: Tuple<string, int> t = new Tuple<string, int>(“Hello”, 4); In previous versions you can use System.Collections.Generic.KeyValuePair<K, V> or a solution like the following: public class Pair<T, U> { public Pair() { } public Pair(T first, U second) { this.First = first; this.Second = second; } public T First … Read more

What are the underlying data structures used for Redis?

I’ll try to answer your question, but I’ll start with something that may look strange at first: if you are not interested in Redis internals you should not care about how data types are implemented internally. This is for a simple reason: for every Redis operation you’ll find the time complexity in the documentation and, … Read more

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