Home > Enterprise >  How to create an array of linked lists in java
How to create an array of linked lists in java

Time:11-27

Hello StackOverflow community , I am trying to create the following diagram in java : enter image description here

There is Cellule Class ( cell which contains : an unknown type attribut named val , an integer named val , and a pointer to another Cell named next ) , and the DictionnaireHacahge Class which declares a pointer to an array of Cellule named dictH which I am trying to instanciate further in the **constructor **. PS: the two class are in the same package inf353 . but when I am trying to code it with java I am facing a problem in the constructor : the constructor the error : enter image description here

and here is the code : Cellule.java :

package inf353;

public class Cellule<T>{
        public T val;
        public int index ;
        public Cellule next;

        public Cellule() {
            super();
        }

DictionnaireHachage class :

package inf353;

public class DictionnaireHachage implements Dictionnaire{
    Cellule<String>[] dictH ;
    int index = 0;
    public void DictionnaireHachage(){
        dictH = new Cellule<String>[100];
        index=0;
    }

CodePudding user response:

It is not possible to create an array with diamond:

Cellule<String>[] arr = new Cellule<String>[10];

But the good news. We all know (I hope), that diamond operations are live only at compile time. At runtime there're always Object. So you can create the array not using diamond:

Cellule<String>[] arr = new Cellule[10];

P.S. It is better to use List<Cellule<String>> instead

  •  Tags:  
  • java
  • Related