英文:
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<Integer> List1 = new ArrayList<>();
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<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();
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论