在一个CSV文件中添加一列整数(JAVA)。

huangapple go评论83阅读模式
英文:

Add a list of integers into a csv file (JAVA)

问题

以下是翻译好的部分:

我只想从一个非常长的算法中添加一系列数字(这里不会显示算法,但给出了一个输出:[2039,25553,189030,1449869,134295,352258,1588788,718293,353578,1495712,539563,1691741,1032543,362844,1143463,4671463])

List<Integer> List1 = new ArrayList<>();

到一个 CSV 文件中,并从中生成折线图。
我已经搜索了一些答案,但我找不到特定于这个问题的内容。
非常感谢任何帮助!

英文:

All I want is to add a list of numbers from an algorithm (which is really long so I won't show it here but gave an output of [2039, 25553, 189030, 1449869, 134295, 352258, 1588788, 718293, 353578, 1495712, 539563, 1691741, 1032543, 362844, 1143463, 4671463])

List&lt;Integer&gt; List1 = new ArrayList&lt;&gt;();

to a csv file and produce a line graph from it.
I've done some searching for answers but I couldn't find anything specific for this.
Any help will be much appreciated, thank you!

答案1

得分: 1

public class Try
{
    public static void main(String[] args) throws IOException
    {
        List<Integer> List1 = new ArrayList<>();

        //For the example, i populate the list
        List1.add(123);
        List1.add(456);
        List1.add(789);

        PrintWriter outFile = new PrintWriter(new FileWriter("outNumbers.csv"));

        List1.stream().forEach(i->outFile.print(i + ", "));

        outFile.close();
    }
}
英文:
public class Try
{
    public static void main(String[] args) throws IOException
    {
        List&lt;Integer&gt; List1 = new ArrayList&lt;&gt;();
        
        //For the example, i populate the list
        List1.add(123);
        List1.add(456);
        List1.add(789);

        PrintWriter outFile = new PrintWriter(new FileWriter(&quot;outNumbers.csv&quot;));

        List1.stream().forEach(i-&gt;outFile.print(i + &quot;, &quot;));

        outFile.close();
    }
}

huangapple
  • 本文由 发表于 2020年4月7日 05:14:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/61069095.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定