'How do you compare two char arrays with each other to see if the inputted one has more than one specific variable than the other?
Okay, so I'm coding a program that will tell the user if the word they put into the command line is an isogram or not, and I'm having difficulties.
How exactly do I go about making it to where the user inputted char array is compared against the other to see if it has more than one letter than the other?
I have this and I'm confused where to go from here.
char[] alphabet = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char[] wordLetters = word.toCharArray();
boolean blnResult = Arrays.equals(alphabet,wordLetters);
I'm sure I went in the completely wrong way with this, but how should I go about comparing the two to get that result?
Solution 1:[1]
Basically isograms are word or phrase without a repeating letter.
Your function signature or program output expectation in the form of code would help answer better.
However, considering you're working on a function which returns true or false: Set is the way to go about it. Keep putting the characters in a Set or HashMap and if while inserting in set, the character already exists in set then return the response as false otherwise return true.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Milind Gokhale |