0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ListとIteratorのメモ

Last updated at Posted at 2023-08-20

個人の備忘録メモ(リストで複数行読み込んだ際の次行ブレイク判定のやり方)
@Slf4jアノテーションが付与されている前提

List<String[]> tmpList = new ArrayList<String[]>();

tmpList.add(new String[]{"test01-01", "test01-02"});
tmpList.add(new String[]{"test01-01", "test01-02"});
tmpList.add(new String[]{"test02-01", "test02-02"});
tmpList.add(new String[]{"test02-01", "test02-02"});

for (int i = 0; i < tmpList.size(); i++) {
    String[] data1 = tmpList.get(i);
    
    if (i < tmpList.size() - 1) {
        String[] data2 = tmpList.get(i + 1);
        if (!data1.equals(data2)) {
            log.info("break list");
            break;
        }
    }
}

Iterator<String[]> tmpIterator = tmpList.iterator();

while (tmpIterator.hasNext()) {
    String[] data1 = tmpIterator.next();
    
    if (data1 != null) {
        if (tmpIterator.hasNext()) {
            String[] data2 = tmpIterator.next();
            
            if (data2 != null) {
                if (!data1.equals(data2)) {
                    log.info("break iterator");
                    break;
                }
            }
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?