2013-11-20 42 views
0

- 我已經編寫了圖形連接與否的代碼。我得到這行的編譯錯誤valueInList =(Integer)adjacencyList [i] .next();說方法next()沒有爲ArrayList定義圖形連接

- 如何解決這個問題?

private boolean checkCondition2(ArrayList<Integer> [] adjacencyList,int no_of_vertices){ 
     int i,valueInList; 
     boolean checkFlag; 
     tempList = new ArrayList<Integer>(); 
     tempList.add(1); 
     for(i=0;i<no_of_vertices-1;i++){ 
      checkFlag = false; 
      Iterator<Integer> itr = adjacencyList[i].iterator(); 
      while(itr.hasNext()){ 
       valueInList = (Integer) adjacencyList[i].next(); 
       if(!tempList.contains(valueInList)){ 
        tempList.add(valueInList); 
        checkFlag = true; 
        break; 
       } 
      } 
      if(checkFlag==false) 
       return false; 
     } 
     return true; 
    } 

回答

0

使用Iterator本身,而不是從數組元素

valueInList = itr.next(); 

注:如您使用的是通用型的迭代器

0

ArrayList中沒有無需鑄造「 next()「方法,因此代替

valueInList = (Integer) adjacencyList[i].next(); 

你應該有

valueInList = (Integer) itr.next();