Advertisement
Hiteshw11

Check If Two Strings Are Anagrams

Nov 20th, 2024 (edited)
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.35 KB | Source Code | 0 0
  1. void main() {
  2.   String s1 = "Listen";
  3.   String s2 = "Silent";
  4.   s1 = s1.toLowerCase();
  5.   s2 = s2.toLowerCase();
  6.  
  7.   List<String> s11 = s1.split("");
  8.   List<String> s22 = s2.split("");
  9.   s11.sort();
  10.   s22.sort();
  11.   if (s11.join() == s22.join()) {
  12.     print("The strings are anagrams");
  13.   } else {
  14.     print("The strings are not anagrams");
  15.   }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement