JTGT is a Java library for loading, manipulating, and writing Praat TextGrid files, and similar annotation files, such as XWaves lab. It's inspired by the TextGridTools module for Python.
String tgStr = new File("path/to/my.TextGrid").getText();
TextGrid tg = new TextGridSerializer().fromString(tgStr);
for (Annotation annot : tg.getTiers().get(0).getAnnotations()) {
System.out.println(annot.getText());
}