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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:04:07+00:00 2026-06-08T05:04:07+00:00

I have a Text File having following lines 1) 2,3 3,2 4,5 2) 1,3

  • 0

I have a Text File having following lines

1) 2,3 3,2 4,5

2) 1,3 4,2 6,13

3) 1,2 4,2 5,5

4) 1,5 2,2 3,2 5,4 7,3 6,6

The number of lines of the text file is known (i,e 4). The pair digits (for eg : 2,3) are variable for each line. Whereas the pair digit corresponds to the property.

So, to represent these values i am planning to have an array of linked list of an array.

The reason for this choice of mine is that:

1 : Since i know the number of lines is 4. So it will be an array.

2 : Each line has a variable number of pairs. So, i will have a linked list representation for it.

3 : The pair values each represents a property so i will have an array size two for it. One index for each property.

Considering the above three points, I will have an Array(size 4) of LinkedList of an Array(size 2).

Here is how i have represented this in Java(I am new to Java and i have to confess that i do not know yet if its correct ).

static ArrayList<Integer[]>[] graph = (ArrayList<Integer[]>[]) new ArrayList[200];

Now, considering my above graph variable has been initialized properly can some one tell me how can i populate it with the data. If you have some other advice regarding the initialization or how i have conceptually broken the problem in 3 points please share.

  • 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-08T05:04:09+00:00Added an answer on June 8, 2026 at 5:04 am

    Though your thinking process is comprehensible, I think you have come to incorrect decisions (maybe caused by your lack of Java experience) – here are the answers I suggest:

    1. You know that the number of lines is constant with a known constant, but using arrays in Java directly is mostly not useful, use ArrayList instead. It is a List (a tuple) implemented using an array.
    2. Your thought on modeling the pairs of variable amount as a list seems very good and I would agree to this. You should, however, not use a LinkedList for this purpose, as it is generally slower than an ArrayList. Both implementations satisfy the List interface so you can use them interchangeable.
    3. You could model the pairs themselves as two element arrays, but to make the semantics more understandable, you should invent a documented data class for the two parts.

    Now, let’s assume the container type would look like this (you should give the variables and the class itself better names):

    class Pair {
      public final int a;
      public final int b;
    
      Pair(int a, int b){
        this.a = a;
        this.b = b;
      }
    }
    

    You could then create your data structure with:

    final int lines = 42; // the number of lines
    List<List<Pair>> data = new ArrayList<List<Pair>>(lines);
    

    And fill it with data using

    for(String line : input){
      final List<Pair> lineList = new ArrayList<Pair>();
      lineList.addAll(extractPairsFromLine(line));
      data.add(lineList);
    }
    

    where extractPairsFromLine is a method taking a String and returning a List<Pair>.

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

Sidebar

Related Questions

I have a text file having words that i need to validate. After following
I have a .txt file having some text. I want to read this file
I'm having trouble with PHP text parsing I have a txt file which has
I am having utf-8 encoded file containing arabic text and I have to search
I have text file with something like first line line nr 2 line three
I have the following problem. I have a list of different text lines that
I have text file with some stuff that i would like to put into
I have Text file that contains data separated with a comma , . How
I have text file, like FILED AS OF DATE: 20090209 DATE AS OF CHANGE:
I have text file with some text information and i need to split this

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.