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

  • Home
  • SEARCH
  • 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 3404326
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:22:09+00:00 2026-05-18T05:22:09+00:00

i dont’t use java very often and now i got some Problem. I want

  • 0

i dont’t use java very often and now i got some Problem.
I want to read a CSV file like this one:

A,B,C,D
A,B,F,K
E,F,S,A
A,B,C,S
A,C,C,S

Java don’t know dynamic arrays, so i choose an ArrayList. This works so far. The Problem is:
How can I store the ArrayList? I think an other ArrayList would help.
This is what I got:

    BufferedReader reader = new BufferedReader(
            new InputStreamReader(this.getClass().getResourceAsStream(
                    "../data/" + filename + ".csv")));

    List rows = new ArrayList(); 

    String line;
    while ((line = reader.readLine()) != null) {

        rows.add(Arrays.asList(line.split(",")));

    }

Now I get an ArrayList with a size of 5 for rows.size().
How do I get row[0][0] for example?

What do I want to do? The Problem is i want to find the same row except the last column.
For example i want to find row 0 and row 3.
thank you very much

Thank you all! You helped me a lot. =) Maybe Java and I will become friends =) THANKS!

  • 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-18T05:22:10+00:00Added an answer on May 18, 2026 at 5:22 am

    You don’t need to know the row size in advance, String.split() returns a String array:

    List<String[]> rows = new ArrayList<String[]>(); 
    
    String line = null;
    while((line = reader.readLine()) != null)
        rows.add(line.split(",", -1));
    

    To access a specific row:

    int len = rows.get(0).length;
    String val = rows.get(0)[0];
    

    Also, are you always comparing by the entire row except the last column? You could just take off the last value (line.replaceFirst(",.*?$", "")) and compare the rows as strings (have to be careful of whitespace and other formatting, of course).

    A slightly different way:

    Set<String> rows = new HashSet<String>(); 
    
    String line = null;
    while((line = reader.readLine()) != null){
        if(!rows.add(line.substring(0, line.lastIndexOf(','))))
            System.out.println("duplicate found: " + line);
    }
    

    Of course, modify as necessary if you actually need to capture the matching lines.

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

Sidebar

Related Questions

dont want to use css frameworks like 960 cause that will lock the width.
Some people want to see the DB structure and dont have VS, is there
I dont know if I should use the httpcontext caching or the Enterprise Library
I dont know if I'm right, but allmost everytime I read about obfuscation and
Ive decided that I really dont like microsoft and their ways. Please could you
Im new to programming and I dont know very much about but I'm making
Do Pagemethods and Json have security risks?(I dont use cookies).Forexample i have a pagemethod
I've got a string that has curly quotes in it. I'd like to replace
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.