If you need to get a list of keytab principals through Java code, you can use the sun.security.krb5.internal.ktab.KeyTab
class:
KeyTab keyTab = KeyTab.getInstance(keyTabFilePath);
Set<String> principals = Arrays.stream(keyTab.getEntries())
.map(KeyTabEntry::getService)
.map(s -> String.join("@", s.getNameString(), s.getRealmAsString()))
.collect(Collectors.toSet());
log.info("principals={}", principals);

If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.
If I saved your day, you can support me 🤝