1

次のテキストファイルがあります。

10/23/2013  47  34  23  31  03  13  
10/19/2013  33  09  56  54  57  05  
10/16/2013  03  42  26  34  28  27  
10/12/2013  10  58  26  57  08  04  

Scanner を使用して日付を ArrayList "DATE" に追加し、残りの数値を別の ArrayList "NUM" に追加することができました (コードを参照)

次のように、ArrayList>「MAIN」または各行をインデックスとして保持する HashMap を構築しようとしています。

メイン[[47,34,23,31,03,13],[33,09,56,54,57,05],[03,42,26,34,28,27],[10,58,26 ,57,08,04]]

以下のコードを使用して目的の結果を得ることができませんでした。目的の結果を得るためにコードを再構築するのに助けが必要です

ありがとうございました。

   public class Grades {

static String line;
static BufferedReader reader;

static String file = "file/Grades.txt";

static ArrayList<ArrayList<String>> MAIN;
static ArrayList<String> NUM ;

static ArrayList<String> DATE ;
static ArrayList rand;

static int index = 0;

public static void main(String args[]) {

    MAIN = new ArrayList<ArrayList<String>>();
    //lotoNum();



    DATE = new ArrayList<String>();



try {
    Scanner scan = new Scanner(new BufferedReader(new FileReader(file)));

    wwhile(scan.hasNextLine()){
        NUM = new ArrayList<String>();

        String token = scan.nextLine();
        String [] line = token.split("  ");


            DATE.add(line[0]);

            for (int i = 1; i < line.length; i++){
                NUM.add(line[i]);
            }
            MAIN.add(index, NUM);
                index++;


                System.out.println(MAIN);

                //NUM.clear();
                //NUM.trimToSize();


        }


        }

    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

}
 }

出力:
[[47, 34, 23, 31, 03, 13]]
[[47, 34, 23, 31, 03, 13], [33, 09, 56, 54, 57, 05]]
[[47 、34、23、31、03、13]、[33、09、56、54、57、05]、[03、42、26、34、28、27]]
[[47、34、23、31、 03、13]、[33、09、56、54、57、05]、[03、42、26、34、28、27]、[10、58、26、57、08、04]]

4

1 に答える 1