Adding words and checking in Arraylist Hangman

Adding words and checking in Arraylist Hangman

By : Nasafato
Date : November 21 2020, 07:38 AM
I wish did fix the issue. I'm having trouble with adding words and using do while in my code: , Structure your code, e.g. as follows:
code :
static final Scanner in = new Scanner(System.in);
static List<String> words = getStandardWords();

public static void main(String[] args) {
    while (true) {
        System.out.println("-- Hangman --");
        System.out.println("1. 1 Player");
        System.out.println("2. 2 Player");
        System.out.println("3. Add word");
        System.out.println("4. Quit");
        System.out.print("Choice : ");
        String choice = in.nextLine();

        switch (choice) {
            case "1":
            case "2":
            case "3":
            case "4":
                System.out.println("Invalid choice: " + choice);

static List<String> getStandardWords() {
    List<String> result = new ArrayList<>();
    return result;

static void addWord() {
    System.out.println("Input the word to be added: ");
    String word = in.nextLine();

    // add word
    if (words.contains(word)) {
        System.out.println("Already Added");
    } else {

    // add more words?
    while (true) {
        System.out.println("Want to add more words?");
        String choice = in.nextLine();

        switch (choice.toLowerCase(Locale.ROOT)) {
            case "n":
            case "no":
                System.out.println("Thanks for adding");
                // print all words
                for (int i = 0; i < words.size(); i++) {
            case "y":
            case "yes":
                System.out.println("Invalid coice: " + choice);

Share : facebook icon twitter icon
Checking whether a String contains one of the words in an ArrayList

Checking whether a String contains one of the words in an ArrayList

By : Rupali Gangarde
Date : March 29 2020, 07:55 AM
I wish this help you I was working on a program that was outputting glossary terms and definitions in HTML and I want to vary the output based on whether the definition I'm checking has a keyword. To do this I have an ArrayList holding all the keywords I'm looking out for and I was trying to use a foreach loop but it wasn't really working right. Is there a better way to do this. Can someone offer me any pointers with this. I feel it shouldn't be THAT hard. With the HTML bit, I'm trying to output the leading words before the keyword (the keyword is supposed to be HREFED), and then continue past the keyword checking for any more keywords in the definition. , EDIT: After your explanation what you have to do is this:
code :
String valueTwoWords [] = valueTwo.split(" "); // if value = "I went" 
                                               // valueTwoWords = ["I","went"]
for(String getTerm : checkValues)
    for(int i = 0; i < valueTwoWords.length(); i++)
       if(valueTwoWords[i].compareTo(getTerm) == 0) // If the words are the same.
            int foundTermPosition = valueTwo.indexOf(getTerm); 
            lead = valueTwo.substring(0, foundTermPosition-1);
            index = valueTwo.length() - lead.length();

            leftOver = valueTwo.substring(foundTermPosition+getTerm.length(), valueTwo.length());

            out.write("<A HREF=\"#" + getTerm + "\">" + getTerm + "</A>");
            out.write(leftOver + "\n");
            i = valueTwoWords.length() + 1; // getting out of the cycle.
String correct = getTerm + " ";
if (valueTwo.contains(getTerm))
    String s1 = "hi";
    String s2 = "hi";
    String s3 = "hi ";
public int compareTo(Object o)
if (valueTwo.compareTo(getTerm) == 0)
// do something
Hangman checking logic

Hangman checking logic

By : Indiaga
Date : March 29 2020, 07:55 AM
it fixes the issue Hi I am new to programming and we have an assignment to create a hangman game. Now the problem I am having is the guessing. The program is guessing everything right and it's working correctly. though it doesn't print out the letters in the JTextField, or it rather does print out 1 letter but when i guess correct again the previous letter gets overwritten. , You should change the way you initialize display secret from
code :
String displaySecret = "";
    for (int i = 0; i < random.length(); i++)
        displaySecret += "*";
String displaySecret = wordField.getText();
if(displaySecret=NULL){/*case for fist execution*/
    for (int i = 0; i < random.length(); i++)
    displaySecret += "*";
if (guess2 == random.charAt(i))
Split ArrayList of sentences into words, store the words into new ArrayList

Split ArrayList of sentences into words, store the words into new ArrayList

By : kazi develop
Date : March 29 2020, 07:55 AM
will help you I've done some research, and maybe I'm just not asking the right questions. , Solution:
code :
public ArrayList<String> getRawWords(String s) 
   String[]  s2 = s.split(" ");
   ArrayList<String> words = new ArrayList<String>();

   for(int x =0; x< s2.length-1;x++)
   return words;
String sentence = "A Test Sentence";
ArrayList<String> q = new ArrayList<String>();
q = getRawWords(sentence);
Checking if the ID of an element in an ArrayList is already there before adding it

Checking if the ID of an element in an ArrayList is already there before adding it

By : user3189558
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Your ArrayList has type ParkingSlot, but you are using .contains with type String. It returns false anyway. You can add a new method that will check if there is a car with a certain number in the park:
code :
public boolean hasParkingSlot(String searching) {
  for(ParkingSlot slot : slots) {
    if(slot.getID().equals(searching)) return true;
  return false;
Adding all the words from a .txt file to an ArrayList of Custom objects

Adding all the words from a .txt file to an ArrayList of Custom objects

By : user3732844
Date : March 29 2020, 07:55 AM
this will help I have a .txt file in which every line has a single word. I've created a class called Word with a string variable and ArrayList variable. My objective is to loop through the entire .txt file and store every word in there as an Word object. For example, if the word is "philly", then an object of the class Word would be created with the String philly and a Character ArrayList would be created as [p,h,i,l,l,y]
code :
import java.util.ArrayList;

public class Word {

    String wordName;
    ArrayList<Character> uniqueLetters;

    public Word(String wordName, ArrayList<Character> uniqueLetters) {
        this.wordName = wordName;
        this.uniqueLetters = uniqueLetters;

    public Word(String string) {
        ArrayList<Character> tempArray = new ArrayList<Character>();

        for (int i = 0; i < string.length(); i++) { 

        this.wordName = string;
        this.uniqueLetters = tempArray;

objectArray.add(new Word(strLine));
Related Posts Related Posts :
  • How to query using objectify in Google App Engine app
  • List value is printing address instead of value
  • StringUtils.isBlank return false for null Strings
  • Sent parameter through PATCH android
  • i am not able to clear the code below given using throwable concept in java
  • How to get System time instead of Server time in java?
  • How to push json data into an arrya object in MONGO DB by java
  • Saving RelationshipEntity not working
  • Error on "instanceOf" when checking a subClass
  • Java - Splitting a image into 4 images
  • "Pinging" a server in Java
  • RoboGuice Proguard CreationException
  • Android Array list returns Null after adding values
  • Jar Executable what am I doing wrong?
  • How do I mitigate Connection leak triggered for connection com.mysql.jdbc.JDBC4Connection@11d08960,
  • How do i iterate values from a 2d array using conditions
  • Hide Button in CustomPagerAdapter
  • Java GC: does it ever make sense to call super.finalize() in a class that only extends Object?
  • 64bit HashMap in Java
  • Hibernate wildcard query on two columns
  • Want to Generate Auto Login Program Using Java
  • Spring security Oauth 2 with ajax login and form login
  • Parse findInBackground doesn't add to global arraylist?
  • Remove random item from ArrayList
  • in SpringMVC getMessage from i18n properties in a function outside the controller
  • How do I add JCheckBox next to each name that has been entered into an arraylist from a JTextField?
  • Return node ID along with complete node
  • InvocationTargetException. Cannot cast class X to class X. When invoked in Scala Imain through spark-submit
  • how to print elements of a 1D array into a N x N box
  • How to map csv file to pojo class in java
  • How, in Java, to encode default vhost %2F in URL/URI so it doesn't get changed to slash and fail to work
  • Tomcat 5.5 https configuration in Windows Server 2008 64bit
  • Enabling FIPS 140-2 compliance mode in MULE ESB
  • How to pass String PackageName to PkgName under parseXML() and run XMLParser class as a new activity when click on list
  • Error while creating spring -hibernate configuration file
  • Hand off control between java threads
  • NoClassDefFoundError: scala/collection/Seq
  • Getting stack overflow error on one machine but not the other on the same code
  • How can I loop AsyncAjaxRequest in GWT?
  • Failed to find provider info for urbanairship.provider
  • Android ListView Adapter Crash issue/Duplicates
  • Displaying Splash screen only once on user preference
  • Loop List<WebElement> doesn't stop despite no more WebElements
  • Check if pattern exists in a String
  • Swing - Key Problems (Arrow Keys, Tab, etc.) in GUIs with TextComponents
  • Why the solution for binary search tree validity is not working?
  • Double encrypting 2048 RSA?
  • create junit test for runnable class
  • Unable to read and sort information from a text file in Java
  • My device isn't getting detected in android studio (driver issue)
  • Representing a Graph in Java
  • How to XML mapping using jxls
  • Quick Sort stackoverflow error for large arrays
  • Parsing Apache Tika XML Output returns Unknown Tag
  • java simple UI loop, can't find bug
  • how to use greater than and less than in a single if statement in java
  • Error:(27, 13) Failed to resolve: com.antonyt.infiniteviewpager:library:1.0.0
  • Gradle dependencies on source set of different projects
  • Session Scope in Restful Spring Services
  • Java: Change a value in an overridden method of a different class to a value that was calculated in the class
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co