From 052e3917c0b2f3ca52bdf624d4b9a4cf221a8f50 Mon Sep 17 00:00:00 2001 From: Kelechi A <119893584+kakabuogu@users.noreply.github.com> Date: Sun, 30 Apr 2023 15:25:15 -0400 Subject: [PATCH] Create AnagramNew.java --- AnagramNew.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 AnagramNew.java diff --git a/AnagramNew.java b/AnagramNew.java new file mode 100644 index 0000000..fb62b57 --- /dev/null +++ b/AnagramNew.java @@ -0,0 +1,19 @@ +import java.util.HashMap; + +public class Anagram { + public static boolean anagram(String oneS, String twoS) { + HashMap oneHM = new HashMap(); + HashMap twoHM = new HashMap(); + for (char c : oneS.toCharArray()) { + oneHM.put(c, true); + } + for (char c : twoS.toCharArray()) { + twoHM.put(c, true); + } + return oneHM.equals(twoHM); + } + + public static void main(String[] args) { + System.out.println(anagram(args[0], args[1])); + } +}