-1

私の問題はこれです

Scanner sf = new Scanner(f);
ArrayList<String> teamArr = new ArrayList<String>();
int counterPopulate = 0;

while(sf.hasNextLine()){
    teamArr[counterPopulate] = sf.nextLine();
    counterPopulate++;           
}

任意のソリューション、これは try キャッチで囲まれています。この部分で問題を取得teamArr[counterPopulate] = sf.nextLine();

4

2 に答える 2

1

を使用しているようArrayList<String>に、メソッドを使用して新しいオブジェクトをadd(String value)に追加します。StringArrayList

あなたの問題の簡単な解決策を以下に示します。

言語がJAVAであると仮定します。

Scanner sf = new Scanner(f);
ArrayList<String> teamArr = new ArrayList<String>();

while( sf.hasNextLine() ) {
    teamArr.add(sf.nextLine());
}

詳細についてはArrayList、以下Collectionを参照してください。

http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html

于 2013-10-24T15:05:16.003 に答える