2016-10-27 2 views
0

초보자 용코더입니다.벡터 요소 개체 반복

누군가 내게 저장된 벡터 내부 값을 가져 오는 방법을 가르쳐 줄 수 있습니까? 1 [3]? 나는 많은 방법을 시도했지만 난 단지 루프

을 편집 storedVector 객체 내부의 값 storedVector 통해 할 수 없습니다 "데이터"를를 내가 벡터를 생성

tableData.java

public class TableData { 
    static Vector storedVector = new Vector(); 


    public void fillSortedData(File file, Vector data){ 
     Workbook workbook = null; 
     Calendar now = Calendar.getInstance(); 
     int monthnow = now.get(Calendar.MONTH) + 1; 
    try { 
     try { 
      workbook = Workbook.getWorkbook(file); 
     } catch (IOException ex) { 
      Logger.getLogger( 
        excelTojTable.class.getName()).log(Level.SEVERE, null, ex); 
     } 
     Sheet sheet = workbook.getSheet(0); 
     headers.clear(); 
     for (int i = 0; i < sheet.getColumns(); i++) { 
      Cell cell1 = sheet.getCell(i, 0); 
     headers.add(cell1.getContents()); } 
    data.clear(); 
    for (int j = 1; j < sheet.getRows(); j++) { 
     Vector d = new Vector(); 
     for (int i = 0; i < sheet.getColumns(); i++) { 
      Cell cell = sheet.getCell(i, j); 
      d.add(cell.getContents()); 

      CellType type = cell.getType(); 
      if(type == CellType.DATE){ 
       String cellDateStr = cell.getContents(); 
       DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); 
       try { 
        Date cellDate = formatter.parse(cellDateStr); 
        int month = cellDate.getMonth() + 1; 
        if(monthnow != month) { 
         d.clear(); 
         //d.removeAllElemen8ts(); 
         i = sheet.getColumns(); 
        } 
       } catch (ParseException ex) { 
        Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex); 
       } 
      } 
     } 
     if(d.isEmpty() == false) { 
      d.add("\n"); 
      data.add(d); 
      storedVector.add(d); 
     } 
    } 
    } catch (BiffException e) { 
e.printStackTrace(); 
} 
} 
    public void emailList() { 
    int abc = storedVector.size(); 
//iterate through the vector and get all the element 

    } 
} 
} 

사용 다른 java 클래스의 storedVector와 같은 메소드입니다. tableData.java에서

, 나는 반복 할 수있는 방법 "이메일 목록"을 작성하고 그림에 표시했다 모든 이메일을 얻을 목록 또는 배열에 저장하고 싶었

Image of my problem that i want to iterate

+1

이 storedVector' 우리가 내가 작업하고있는 자바 클래스를 추가 그것은 –

+0

의 정확한 유형을 알려 선언하는 방법을 '우리를 보여 사용해보십시오. 도움이 될지 확실하지 않습니다. 미안합니다. – SING93

답변

1

경우 storedVector이 목록입니다/Vector 세트,이 코드가 도움이 될 수 있습니다

for(Vector vector: storedVector){ 
     for(int i=0; i< vector.size(); i++){ 
     //access to vector[i] 
     } 
    } 
1

벡터 AbstractList를 확장합니다. 따라서 Vector.get (i) 메서드가 있어야합니다.

Vector v = storedVector.get(1); 
Object o = v.get(3);