
How to Verify All Unique Characters in Strings in 15 sec #coding #shorts #interviewtips
1733
14________
Learn how to check if all characters in a String are unique using just one line of Java code with Streams API!
This is one of the most asked coding interview questions, and we solve it in just 20 seconds ⏱️
💡 Code:
String str = "abcdd";
boolean isUnique = str.chars().distinct().count() == str.length();
System.out.println(isUnique);
📌 This program uses distinct() and count() to compare the number of unique characters vs total characters.
If they match, the string is unique
コメント