如何对数组中的多个索引进行排序并根据值对其进行编码?

时间:2017-10-25 21:28:55

标签: java

所以,我有一个循环遍历数组然后执行try / catch以查看是否可以从原始字符串值中获取任何索引。

for (int i = 0; i < recordLine.split("\t").length; i++) {
    try {
        long l = Integer.parseInt(recordLine.split("\t")[i]);
    } catch (NumberFormatException numberFormatException) {
        System.out.println("Here are the Strings: " + i);
        System.out.println("NumberFormatException: " + numberFormatException.getMessage());
    }
}

1 个答案:

答案 0 :(得分:0)

    String[] splitRecordLineItems = recordLine.split("\t");
    Character[] resultsArray = new Character[splitRecordLineItems.length];

    for (int i = 0; i < splitRecordLineItems.length; i++) {
        try {
            long l = Long.parseLong(splitRecordLineItems[i]);
            resultsArray[i] = 'L';
        } catch (NumberFormatException nfe) {
            resultsArray[i] = 'S';
        }
    }

然后,您可以使用以下行打印resultsArray的内容:

System.out.println(Arrays.toString(resultsArray));