0

i am new to java. Down below i created an ArrayList of LinkedList objects (atleast i thought i did) but when i tried to add something to the Linked-List object the add method function isn't working(in addedge function), it seems like the it returns an "Object type"(Java.lang.Object).

public class DirectedGraph {
private int Nvertices;
private ArrayList LLA, Source;
private final String Tgraph= "Directed";

private DirectedGraph(int nvertices) {
    this.Nvertices = nvertices;
    LLA = new ArrayList();
    Source = new ArrayList();
    for (int i=0;i<nvertices;i++){
        LLA.add(new LinkedList<String>());
    }
}
public void addvertex(String Vtx){
    Source.add(Vtx);
}
public void addedge(String Source, String Edge){
    LLA.get(Source.indexOf(Source)).add(Edge);//Error cann't resolve add(java.lang.String).

    //Also tried  LinkedList<String> jk = LLA.get(Source.indexOf(Source)); it returns the type Object.

}
}
Hashik
  • 191
  • 1
  • 1
  • 7
  • Hey, Sortirios thanks :) and is there a way i can convert a raw type in to what ever type i want? – Hashik Sep 22 '17 at 00:24
  • you may need to qualify `LLA` as a list of something: `LLA = new ArrayList()`. As duplicate mentions: you have a bag. Is it a a bag of apple? of pear? of potatoes? – Al-un Sep 22 '17 at 00:48

0 Answers0