小编dan*_*101的帖子

为什么我一直只获得Java ArrayList中的最后一个对象值?

我已设法将所有对象放入arraylist但我无法打印所有值.无论使用何种方法,都只打印最后一个.

它不是仅通过ArrayList打印,这让我想知道推送的对象是否相同. 

如果是,我该如何改变?我已经附加了程序(运行FileInput.java):

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;

import javax.swing.text.html.HTMLDocument.Iterator;

//lecture notes(L1) method
public class FileInput {
    static String first;
    static String second;
    static String third;
    static String fourth;
    static String fifth;
    static String sixth;

    static int num = 1;
        public static void main(String[] args)throws FileNotFoundException, IOException{
        Scanner input = new Scanner(new File("player.txt"));
        String data = null;

        PrintWriter output = new PrintWriter("outfile.txt");

        // Player1 user = new Player1();

        ArrayList<Player1>listOfPlayers = new …
Run Code Online (Sandbox Code Playgroud)

java arrays class list arraylist

-1
推荐指数
1
解决办法
1287
查看次数

标签 统计

arraylist ×1

arrays ×1

class ×1

java ×1

list ×1