title: inter-linked list in java
body: <p>In a "flat" linked list structure each object is linked to the next object by a single pointer. </p>
  
  <p>What i am looking for is a way to have a set of nodes, and let them be interconnected in a linked-list fashion.</p>
  
  <pre><code>class Person{
      public Person next;
      private String name;
  
      //Contructor method et. cetera. 
  }
  
  class List{
    private Person personlist, lastperson;
    private int counter;
  
    List(){
      Person lh = new Person("LISTHEADER");
      personListe = lh;
      sistePerson = lh;
    }
    //insert getters and setters ++.
  }
  </code></pre>
  
  <p>In other instances it would be natural to include a pointer to the previous object too. But what if all the nodes in the list need to be inter connected? </p>
  
  <p>Lets say i have three person objects; A, B, C, and i want to make a list that holds each of the persons friends. Let's say
  A is friends with B and C.
  B is friends with A and C.
  C is friends with A and A.</p>
  
  <p>If i tried to achieve this with the first mentioned linked list structure, it seems it would not be sufficient for a person object to only have one pointer to the next object, since B -> A -> C means that A's next-pointer is pointing at C, so that C -> A-> B is now not possible. </p>
  
  <p>Is there a way to make a data structure similar to the linked list, where instead of having each object pointing to the next object, each object can both hold multiple pointers to other nodes and still be an element in a "list" itself? </p>