Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 538135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:59:59+00:00 2026-05-13T09:59:59+00:00

I am piping in a file and storing it into a treeset. I am

  • 0

I am piping in a file and storing it into a treeset. I am trying to count unique words..
I am placing words that i dont want into a hashset. “a”,”the”, “and”

I want to check to see if the file contains those words, before i place them into
the TreeSet..
i know i need some sort of if(word == find) ? i just dont know how to do it..

Sorry about formatting. its hard to get it correct after you paste.

this is what i have..

import java.util.Scanner;
import java.util.ArrayList;
import java.util.TreeSet;
import java.util.Iterator;
import java.util.HashSet;

public class Project1
{
    public static void main(String[] args)
    {
        Scanner     sc = new Scanner(System.in);    
        String      word;
        String grab;
        int count = 0;
        int count2 =0;
        int count3 =0;
        int count4 =0;
        int number;
        TreeSet<String> a = new TreeSet<String>();
        HashSet<String> find = new HashSet<String>();

        System.out.println("Project 1\n");
        find.add("a");
        find.add("and");
        find.add("the");

        while (sc.hasNext()) 
        {   
            word = sc.next();
            word = word.toLowerCase();
            for(int i = 0; i < word.length(); i++ )
            {
                if(Character.isDigit(word.charAt(i))) 
                {
                    count3++;  
                }
            }
            //if( a.contains("a") )
            //|| word.matches("and") || word.matches("the")|| word.contains("$"))
            //{
            //   count2++;
            // }
            a.add(word);
            if (word.equals("---"))
            {
                break;
            }
        }

        System.out.println("a size");
        System.out.println(a.size());
        // count = count2 - count;
        System.out.println("unique words");
        System.out.println(a.size() -  count2 - count3);
        System.out.println("\nbye...");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:59:59+00:00Added an answer on May 13, 2026 at 9:59 am

    I see you’re using SO for the whole project.

    You can do something along the lines of:

    if(!find.contains(word)){
        //addTheWord
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm extracting fields from Active Directory and piping that into a .csv file, My
Is piping parameter into line is working only for functions that accept one parameter?
I am trying to implement a linux shell that supports piping. I have already
So I'm dealing with a csv file that has missing values. What I want
I'm trying to run a command-line program and piping in a file. The command
Using a msdos window I am piping in an amazon.txt file. I am trying
I am trying to put the content of a file into a variable, this
I'm trying to write a Powershell function that takes an array argument. I want
I'm dumping a database into a file (piping the dump through gzip) and it
I need to write a batch file that is piping the output of SQLCMD

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.