How to create recursive tree-like data structure in java using Map<String, T>?

  • A+

I have a mind-block when trying to create data-structure that follows the pattern:

Map<String, T> is a main building block and T is either Map<String, T> or as terminal operator List<String>. Is it possible to build anything similar in Java, this idea comes from functional languages like F# or Haskell-like.

I searched SO but so far couldn't find anything that match my idea in Java.


Yes: you can do something like this:

public abstract class T { ... } public class NonTerminal extends T {     private Map<String,T> map = new HashMap<>(); ... } public class Terminal extends T {     private List<String> list; --- } 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: