@Override
        public int compare(TopicIdPartition topicPartition1, TopicIdPartition topicPartition2) {
            String topic1 = topicPartition1.topic();
            String topic2 = topicPartition2.topic();

            if (topic1.equals(topic2)) {
                return topicPartition1.partition() - topicPartition2.partition();
            } else {
                return topic1.compareTo(topic2);
            }
        }
Comparison based on topic name and partition number.
clients/src/main/java/org/apache/kafka/clients/consumer/internals/Utils.java