Note that there are some explanatory texts on larger screens.

plurals
  1. POcompare input to an object arraylist
    primarykey
    data
    text
    <p>I would like to compare the input from a JTextField to all the elements in a string arraylist. If the input is equal to an element in the list I would like the program to acknowledge by saying "This is in my vocabulary.", and if it is not, I would like the program to say "This is NOT in my vocabulary." In my code, I have tried getting this to work buy I always get the message "This is NOT in my vocabulary." even if the input matches an element in my list. How can I get this to work properly?</p> <p>Here is my code, in it AI is where the list that is being compared is.</p> <pre><code>package Important; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JTextField; import AI.*; public class TextActions implements ActionListener{ private String hero; private Vocabulary vocab1 = new Vocabulary(); public void actionPerformed(ActionEvent e) { e.getSource(); hero = e.getActionCommand(); if (vocab1.Adjectives.equals(hero)){ System.out.println("This word is in my vocab"); }else{ System.out.println( hero + " is not in my vocab"); } //CompareWords(hero); } public void CompareWords(String readme){ if (vocab1.Adjectives.contains(readme)){ //System.out.println("This word is in my vocab"); } } } </code></pre> <p>Here is the Vocabulary class as requested.</p> <pre><code>package AI; </code></pre> <p>import java.util.*;</p> <p>public class Vocabulary {</p> <pre><code>//String[] thoughts; public List&lt;String&gt; Adjectives = new ArrayList&lt;String&gt;(); public void AddWord(int ArrayListNumber, String WordEntered){ if(ArrayListNumber == 1){ Adjectives.add(WordEntered); } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload