2009-03-24 3 views
0

배열에 저장된 파일을 다른 클래스로 보내려면 어떻게해야합니까? 이 코드를 시도했지만 작동하지 않습니다.배열 파일을 다른 클래스로 보내는 방법

public class abc { 
    .... 
    String [] indexFiles = new String[100]; 

    public abc(){ 
     indexFiles [0]=image1.txt; 
     indexFiles [1]=image1.txt; 
     .... 
     draw = new drawing (indexFiles(0)); // I got error in this code 
     draw = new drawing (indexFiles.get(0)); // I also tried this code but it give me error as well.  
    } 

} 

답변

2

indexFiles[0] 
+0

오! 어떻게 내가 그 [...]을 놓칠 수 .... 감사합니다 프랭크 :-) – Jessy

4

가 드로잉 클래스는 문자열 배열, 또는 단지 하나의 문자열을 가지고 있습니까 사용? 이 배열을 취하는 경우

, 이것을 사용 :

draw = new drawing(indexFiles); 

을이 하나의 문자열을 사용하면을 (를) 사용

draw = new drawing(indexFiles[0]); 

배열에서 하나의 값에 액세스하려면 사용하는 [ ] 괄호, 괄호 안 함.

그냥 사이드 참고 : "(0) GET"방법은 ArrayList를 같은 컬렉션에 사용됩니다 :

List<String> stringList = new ArrayList<String>(); 
stringList.add("MyString"); 
System.out.println(stringList.get(0)); 
관련 문제