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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:36:07+00:00 2026-06-01T17:36:07+00:00

Right now I want to store a text file that goes like this: 1

  • 0

Right now I want to store a text file that goes like this:

1 apple

2 banana

3 orange

4 lynx

5 cappuccino

and so on into a data structure. Would the best way of doing this be mapping the int to the string somehow, or should I make an arraylist? I’m supposed to, when I store the words themselves, disregard the int and any whitespace, and keep only the word itself. How do I disregard the int when reading in lines? Here is my hacked together code right now:

  public Dictionary(String filename) throws IOException {
  if (filename==null)
      throw new IllegalArgumentException("Null filename");
  else{
      try {
            BufferedReader in = new BufferedReader(new FileReader(filename));
            String str;
            int numLines=0;
            while ((str = in.readLine()) != null) {
                numLines++;
            }
            String[] words=new String[numLines];
            for (int i=0; i<words.length;i++){
                words[i]=in.readLine();
            }

            in.close();
        } catch (IOException e) {
    }
  }

}

Thank you in advance for the help!!

  • 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-01T17:36:08+00:00Added an answer on June 1, 2026 at 5:36 pm

    Just implement the power of the regular expression:

    List texts<String> = new ArrayList<String>();
    Pattern pattern = Pattern.compile("[^0-9\\s]+"); 
    String text = "1 apple 2 oranges 3 carrots"; 
    Matcher matcher = pattern.matcher(text); 
    
    while (matcher.find()) { 
      texts.add(matcher.group(0)); 
    } 
    

    regular expressions are very much popular these days. the compile method is used for compiling your search pattern, with the numbers you see in the parameter is to prevent getting them on your search. So it’s completely safe. use apache’s IOUtilities to convert a text file to String

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

right now its set up to write to a file, but I want it
Right now, I have more than 25 vertices that form a model. I want
I want to make an ad banner. Right now i have an imagebutton that
I have this code right now : $(document).ready(function() { var ktitle = $('.hiddentwo').text(); $('div#tab2').load('morefour.php?title=ktitle');
So in our database right now, we can store text, and text only. So,
I would like for my text file that gets created keeps being added to.
so I'm in a little over my head right now and want to verify
I've created a custom view class and right now just want to draw an
I have been writing some rspec tests, and right now I want to verify
Right now when I want to redirect after an action in my controller I

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.