java – Break Loop in hasnext on newline

I have a input like this:

ABC
DEF
GHI

XYZ
MNO
QRZ

I want to read this via hasnext, but want to store them in two separate ArrayList. How can I do that? Like I want to break out of loop at n character, again want to continue afterward. Please help me out. Thanks