从 JComboBox 列表中删除多余的空白和指定的行

remove extra blanks and specified rows from JComboBox list

我正在通过 jComboBox 使用此 code 从文本文件中读取大数据。

文本文件大约有 100 列,我正在使用以下代码阅读必要的列:

(substring(12, 13) 与 - "A, B, C, D, ..." 相关,substring(58, 96) 与 - 相关"Some text")

jComboBox1.addItem(str.substring(12, 13) + str.substring(58, 96));

并且在输出中我得到 jComboBox 空行和空 space。 如图所示,我不需要读取标记为 "AAA" 的行( 蓝线 )和标记为 [=32 的行=]评论(红线)。

我想问一下是否可以删除多余的空格并排除标记为 "AAA" 的行?

提前致谢。

试试这个答案:

for (String str : lines) {
   if ( (!str.startsWith("AAA")) && (!str.substring(12, 13).equals(" ")) )
      jComboBox1.addItem(str.substring(12, 13) + str.substring(58, 96));
}