java - 处理中的Integer类型的动态数组

标签 java arrays processing

如何创建一个在 PROCESSING 中保存整数值(而不是 int)的动态数组。

我已将字符串存储到文本文件中(String Str=“12,13,14,15”)。现在我需要在加载文本文件后将它们拆分并转换为整数类型。

最佳答案

由于代码正在读取文件,因此我将使用 Scanner相反:

    String str = "2,3,4,5,6,7";
    List<Integer> intList = new ArrayList<Integer>();
    Scanner sc = new Scanner(new File(/*yourFile*/));
    //Scanner sc = new Scanner(str);
    while(sc.hasNext()) {
        sc.useDelimiter(",");
        intList.add(sc.nextInt());
    }

    Integer[] wrapperArray = new Integer[intList.size()];
    intList.toArray(wrapperArray);

扫描仪:How-to

关于java - 处理中的Integer类型的动态数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18589820/

相关文章:

java - 从另一个线程调用时变量为空

java - 将 wait 和 notifyAll 代码转换为使用 Java 1.5 Lock 对象

javascript - 如何在 JavaScript 中使用从 csv 文件加载的数据?

c++ - 动态分配自定义类的数组并重载运算符

java - 如何在处理项目中使用Gradle?

java - 试图在线程中按下PopupWindow的按钮

java - 如何不断生成矩形并更新它们AnimationTimer?

javascript - 删除之前淡出列表中的项目

audio - 如何在麦克风中播放声音?

java - 在 Mac 上合并来自 Processing 的 JAR 文件