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 9107649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:37:22+00:00 2026-06-17T02:37:22+00:00

I took a text file and put it in one array. However, I want

  • 0

I took a text file and put it in one array. However, I want to search for a String (word) within the array. In my case I wanted to use the scanner to get input from the user, then search for a string match in the array. How can one achieve such a task?

public static void main(String[]args) throws IOException
{
    //Scanner scan = new Scanner(System.in);
    //String stringSearch = scan.nextLine();
    List<String> words = new ArrayList<String>();
    BufferedReader reader = new BufferedReader(new FileReader("File1.txt"));
    String line;
    while ((line = reader.readLine()) != null) {
                    words.add(line);        
        }
        reader.close();
        System.out.println(words);
}

My output:

[CHAPTER I. Down the Rabbit-Hole, Alice was beginning to get very tired of sitting by her sister on the, bank, and of having nothing to do:]
  • 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-06-17T02:37:24+00:00Added an answer on June 17, 2026 at 2:37 am

    You can use the .contains() function from List. It will use the .equals() method of the parameter on each element

    words.contains("your_string")
    

    Just realized you are saving one line per index, and not one word. In this case:

    for(String sLine : words) {
        if (sLine.contains("your_string")) {
             System.out.println("Got a match");
             break;
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following text file 40 timesteps took 58.320842 seconds greetings 0 80
Question abstract: how to parse text file into two hashes in Perl. One store
I need to move or copy a simple text file from one web site
I have a text file sized 300MB, I want to count the occurrences of
I am trying to serialize a list of dictionaries to a csv text file
I have a php file that creates a json array for my images and
I'm using a FileReader wrapped in a LineNumberReader to index a large text file
Morning, I'm trying to split a large text file (15,000,000 rows) using StreamReader/StreamWriter. Is
i took this code from a different question and my script file has more
I have a large (~100GB) text file structured like this: A,foobar A,barfoo A,foobar B,barfoo

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.