code: public void getTopics(String projectID) {
      logger.log(Level.INFO, "Will try to get topics for project {0} ...", projectID);
  
      ListTopicsRequest request = ListTopicsRequest.newBuilder()
              .setPageSize(10)        // get max 10 topics
              .setProject(projectID)  // for our projectID
              .build();
  
      ListTopicsResponse response;
      try {
        response = blockingStub.listTopics(request);
      } catch (StatusRuntimeException e) {
        logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
        return;
      }
      logger.log(Level.INFO, "Topics list:\n {0}", response.getTopicsList());
    }
docs: Get topics (max 10) for our project ID: the topic list is logged to the logger.
  
  @param projectID  the GCP project ID to get the pubsub topics for. This is a string like
  "projects/balmy-cirrus-225307" where "balmy-cirrus-225307" is
  the project ID for the project you created.