繁体   English   中英

尽管有println,但字符串数组(String [])仍在单行中打印出来

[英]String Arrays (String[ ]) are printing out in a single line despite println

当我将问题[0]打印到TextArea中时,输出如下所示:

Line1Line2

我希望输出看起来像这样:

1号线

2号线

尽管使用了println ,我如何更改输出格式?

编码:

    public void run() {
        try {
            write = new PrintStream(connection.getOutputStream());
            //Skriva till klienten.
            List<String> questionsList = new ArrayList<>();

            try (Stream<String> questionsStream = Files.lines(Paths.get(quizFile))) {  //Reading from text file
                questionsList = questionsStream
                        .parallel()
                        .collect(Collectors.toList());
                Collections.shuffle(questionsList);  //Randomizing the Strings.

                while (true) {

                    for (String string : questionsList) {
                        String[] questions = string.split("/");
                        write.println(questions[0]);  //Printing out [0]."\n" does not seperate the String to seperate lines.
                        try {
                            Thread.sleep(4000); //"Sleeping" between the lines.
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

您应该使用HTML,标记“
'在write.println(questions[0] + "<br>");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM