배열을 사용하여 인용 색인을 만드는 인터페이스를 구현했습니다. 필자는 새로운 프로그래머이며 현재의 Array 구현을 ArrayList 구현으로 변환하는 방법을 배우고 자합니다. 지금까지 제 코드가 있습니다. 배열 대신 printCitationIndex() 메서드에서 ArrayList를 어떻게 사용합니까?배열을 ArrayList로 변환
import java.util.ArrayList;
public class IndexArrayList implements IndexInterface{
ArrayList<Citation> citationIndex = new ArrayList<Citation>();
private String formatType;
private int totalNumCitations, numKeywords;
ArrayList<Keyword> keywordIndex = new ArrayList<Keyword>();
public void printCitationIndex(){
// Pre-condition - the index is not empty and has a format type
//Prints out all the citations in the index formatted according to its format type.
//Italicization not required
if (!this.formatType.equals("")) {
if (!isEmpty()) {
for (int i = 0; i < citationIndex.length; i++) {
if (citationIndex[i] != null) {
if (this.formatType.equals("IEEE")) {
System.out.println(citationIndex[i].formatIEEE());
} else if (this.formatType.equals("APA")) {
System.out.println(citationIndex[i].formatAPA());
} else if (this.formatType.equals("ACM")) {
System.out.println(citationIndex[i].getAuthorsACM());
}
}
}
} else {
System.out.println("The index is empty!");
}
} else {
System.out.println("The index has no format type!");
}
}
}
는'나는 당신의 질문을 이해한다면 제대로 갔지 (I)''로 크기는()'과'[i]는''와 .length' 교체하는 단지 문제입니다 :) – xpa1492