'Comparing Head of Queue to Elements in an Array
I am trying to create a password verification program that takes the user's password, inserts the characters of the password into a queue, and then compares the head of the queue to every element of an array (three arrays, one which contains every letter in the alphabet, one that contains every digit, and on that contains particular special characters). I am trying to find a way to compare the elements, as every time I try to compare, it never seems to recognize when the element in the queue is the same as the element in the array. This is the code I have so far.
The code for the array:
Character[] digitArray = new Character[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
The code for the queue:
default Queue<Character> enqueueTarget(String target) {
target.toLowerCase();
for (char ch : target.toCharArray()) {queue.add(ch);}
return queue;
}
And the code to match the elements:
public boolean iterateDigits(Queue obj) {
int counterDigits = 0;
List<Character> intList = new ArrayList<>(Arrays.asList(digitArray));
while (!obj.isEmpty()){
if (intList.contains(obj.peek())) {counterDigits++;}
obj.poll();
} if (counterDigits > 0){return true;}
else {return false;}
}
Any tips on how I can properly compare and match the elements? Or is there a better way of going about this?
Solution 1:[1]
Found a solution for anyone wondering:
for (Object ch : obj) {
if (Character.isDigit((Character) ch)) {return true;}
}return false;
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 | TripleJ500 |
