XML 파일에서이 코드를 읽습니다. 5 개의 문자열 (groupId, groupType, filePath, author 및 lineNo)을 가져오고 먼저 문자열 배열에 저장합니다. 그런 다음 String Array가 ArrayList에 저장됩니다. 마지막으로, 마지막 "for"는 ArrayList의 내용을 표시합니다.Arraylist와의 문자열 배열 추가 및 가져 오기
콘텐츠를 표시하고 싶을 때 마지막으로 추가 한 문자열 배열이 생기는 문제입니다. 다음은 코드와 출력입니다. 문제가 무엇인지 알아낼 수 있습니까?
ArrayList<String[]> developerTypes = new ArrayList<String[]>();
String[] developerInfo = {null, null, null, null, null};
String[] developerInfoR = {null, null, null, null, null};
String groupId;
String groupType;
String filePath;
String author;
String lineNo;
SAXBuilder builder = new SAXBuilder();
Document doc = (Document) builder.build("A.xml");
Element clones = doc.getRootElement();
// Loop of clones' children (clone_group)
List<Element> parentElements = clones.getChildren();
for(Element parentElement:parentElements){
// Loop of clone_group's children (clone_fragment)
List<Element> elements = parentElement.getChildren();
for(Element element:elements){
// Loop of clone_fragment's children (blameInfo)
List<Element> childelements = element.getChildren();
for(Element childElement:childelements){
groupId = parentElement.getAttributeValue("groupid");
groupType = parentElement.getAttributeValue("type");
filePath = element.getAttributeValue("file");
author = childElement.getAttributeValue("author");
lineNo = childElement.getAttributeValue("lineNo");
//System.out.print(groupId + " - ");
//System.out.print(groupType + " - ");
//System.out.print(file + " - ");
//System.out.println(author);
developerInfo[0] = groupId;
developerInfo[1] = groupType;
developerInfo[2] = filePath.substring(1, filePath.lastIndexOf("."));;
developerInfo[3] = author;
developerInfo[4] = lineNo;
developerTypes.add(developerInfo);
}// for (blameInfo)
}// for (clone_fragment)
}// for (clone_group)
// Display the content of the Arraylist
for(int i = 0; i< developerTypes.size(); ++i){
developerInfoR = developerTypes.get(i);
for(int j = 0; j< developerInfoR.length; ++j){
System.out.print(developerInfoR[j] + " ");
}
System.out.print("\n");
}
아웃풋 :
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
309 Type-3 builtin/update-index.c Jonathan Nieder 704
...
하면, 오류가이 같은 코드를 "단계별"때 신속하게 명백해질 것이다 디버거와 좋은 IDE를 처리하는 방법을 알 필요가 날 것으로 보인다. –