我是java的新手。在下面我创建了一个LinkedList对象的ArrayList(至少我以为我做了)但是当我试图向Linked-List对象添加一些东西时,add方法函数不工作(在addge函数中),它看起来像它返回"对象类型"(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.
}
}