Question:
How to fix this Java Palindrome Stacks and Queue code?
SarahDoesIt
2012-11-11 13:11:36 UTC
I receive an error when trying to compile my Java code for a palindrome.

This is my error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The type Queue is not generic; it cannot be parameterized with arguments

at palindrome5.main(palindrome5.java:13)


This is my code:

import java.util.*;

public class Palindrome2
{
public static void main(String [] args)
{
String input = args[0];
// For ignoring case
String inputString = input.toLowerCase();
// Create stack
Stack stack = new Stack();
// Create queue
Queue queue = new LinkedList();


// Add input string to stack and queue
for ( int i = 0 ; i < inputString.length() ; i++ )
{
stack.push(inputString.charAt(i));
queue.add(inputString.charAt(i));
}

boolean palindrome = true;

while ( !stack.isEmpty() && palindrome == true ) {
if ( Character.isLetter(stack.peek()) && Character.isLetter(queue.peek()) )
{
// Check for comparison
if ( stack.pop().equals( queue.remove() ) == false ) {
palindrome = false;
}

}
else
{
if ( !Character.isLetter(stack.peek()))
stack.pop();
if ( !Character.isLetter(queue.peek()))
queue.remove();

}

}
// Output
System.out.println("Text: " + input );
System.out.println("Palindrome: " + palindrome);
}
}
Three answers:
Rob
2012-11-11 15:02:17 UTC
Works fine for me using the latest Oracle Java 7 JDK. I'd suggest checking to make sure you have the latest JDK installed: that would be my first suspicion for what's wrong.
spry
2016-11-05 03:47:40 UTC
Palindrome Java Code
anonymous
2017-02-25 18:43:39 UTC
Stack: The java.util.Stack classification merits somewhat clarification via itself. interior the textual content fabric on the checklist interface the Stack classification is listed as an implementation. the common use of a Stack isn't as a itemizing nonetheless. A Stack is a records shape the place you upload aspects to the "suitable" of the stack, and additionally get rid of aspects from the right back. it is likewise stated via fact the "final In First Out (LIFO)" concept. in assessment, a Queue makes use of a "First In First Out (FIFO)" concept. Queue: The java.util.Queue interface is a subtype of the java.util.sequence interface. It represents an ordered checklist of gadgets in simple terms like a itemizing, yet its meant use is extremely diverse. A queue is designed to have aspects inserted on the tip of the queue, and aspects removed from the initiating of the queue. in simple terms like a queue in a food market.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...