Get and remove accounts from the token cache using MSAL for Java

MSAL for Java provides an in-memory token cache by default. The in-memory token cache persists for the duration of the application execution.

See which accounts are in the cache

You can check what accounts are in the cache by calling PublicClientApplication.getAccounts() as shown in the following example:

PublicClientApplication pca = new PublicClientApplication.Builder(

Set<IAccount> accounts = pca.getAccounts().join();

Remove accounts from the cache

To remove an account from the cache, find the account that needs to be removed and then call PublicClientApplication.removeAccount() as shown in the following example:

Set<IAccount> accounts = pca.getAccounts().join();

IAccount accountToBeRemoved =
                x -> x.username().equalsIgnoreCase(


Learn more

If you are using MSAL for Java, learn about Custom token cache serialization in MSAL for Java.