Tree problem when trying to display certain set of data

I’m encountering a IllegalArgumentException when trying to display a set of data in my Tree component. I have multiple classes which have attributes inside them and I’m trying to list them in an following hierarchical design:

  • Root class 1
    [list]
  • class 2
    [list]
  • class 3
    [list]
  • class 4

    [/list]

    [/list]

    [/list]
  • Root class 1
    [list]
  • class 2
    [list]
  • class 3
    [list]
  • class 4

    [/list]

    [/list]

    [/list]

etc.

The problem here is, that to achieve this, I am at the moment using Tree and TreeData to display them. This causes a problem, because I can’t add item that has the same content when it is a string. Let me elaborate a bit: I have a class 3 that has a name value, which is the name of a system. Now I have 4 devices that I want to list. Two of them has a system named Windows, for example. Now when I try to list them, I get the error stated above, hence the HashCode is the same, coz the hashcode is calculated by the content of the String. And I am forced to use string because I have no other idea how to display from several classes, since you can only set one TreeData<> and Tree<>.

I’d be delighted to get help. I can provide code, but it is a mess since it is quite vast. Basically, I’m creating the Tree items with for loops that go through a List element where I’ve looked up data I want to show from my database. Nothing too complicated tbh.

Help, please!

Typically we use POJOs or Entities with these data structures. In those case we usually have some internal field like Id there, which is then different even if the other fields may be the same. I guess that is the workaround here too instead of using String directly.