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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:56:53+00:00 2026-05-23T21:56:53+00:00

So for a program I am working on, I am trying to create a

  • 0

So for a program I am working on, I am trying to create a method which will parse through a text file. Using the values within the text file, create an ArrayList within an ArrayList. Here is my code so far:

public ArrayList<ArrayList<String>> getRels(String relsFile)
{
   String[] currentId;
   int i = -1;

   ArrayList<ArrayList<String>> relsList = new ArrayList<ArrayList<String>>();
   relsList.add(new ArrayList<String>());

   try
   {
      // Open the file that is the first 
      // command line parameter
      FileInputStream fstream = new FileInputStream(relsFile);
      BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
      String strLine;

      while ((strLine = br.readLine()) != null)
      {
         // Add values to array list
         currentId = strLine.split(",");
         relsList.get(++i).add(currentId[0]);
         //???????????          
      }   
      //Close the input stream
      in.close();
   }        
   catch (Exception e)
   {
      System.err.println("Error: " + e.getMessage());
   }
   return relsList; 
}

And here is an example of the text file I am looking at.

rId13,image3
rId18,image8
rId26,image16
rId39,image29
rId21,image11
rId34,image24
rId7,image1
rId12,image2
rId17,image7
rId25,image15
rId33,image23
rId38,image28
rId16,image6
rId20,image10
rId29,image19
rId24,image14
rId32,image22
rId37,image27
rId15,image5
rId23,image13
rId28,image18
rId36,image26
rId19,image9
rId31,image21
rId14,image4
rId22,image12
rId27,image17
rId30,image20
rId35,image25

Essentially, I want to be able to split up the values, store all rId values in the first ArrayList, then list their corresponding image values in the nested ArrayList. However, I am kind of stuck and not sure what to do at this point. Could someone help me out? I appreciate any help that is offered.

  • 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-23T21:56:54+00:00Added an answer on May 23, 2026 at 9:56 pm

    I suggest you use a debugger to see exactly what is happening.

    From reading the code I would guess it reads the first line okay but fails after that point because you only add one nested ArrayList but try to use many of them.

    The simplest thing to do is to return Map<String, String> as I assume the first column is unique.

    public static Map<String, String> getRels(String relsFile) {
        Map<String, String> map = new LinkedHashMap<String, String>();
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader(relsFile));
            String line;
            while ((line = br.readLine()) != null) {
                String[] parts = line.split(",", 2);
                if (parts.length > 1)
                    map.put(parts[0], parts[1]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) br.close();
            } catch (IOException ignored) {
            }
        }
        return map;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working through trying to learn to program in Python and am focused
I am using Junit 4. My whole program is working fine. I am trying
I'm trying to create a JavaScript program using the innerHTML function wherein the user
I am trying to create a file in the /tmp directory (working on a
Im working on a program which moves a panel within a form. I use
I am using VS 2010 and i was trying to create program based on
I am trying to create a program that will create a vector, generate 100
I'm currently trying to create a little C/C++ program which emulates a key-press on
I've managed to get my pthreads program sort of working. Basically I am trying
I am trying to create a help panel for an application I am working

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.