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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:31:35+00:00 2026-05-16T17:31:35+00:00

I am reading in a csv file in Java and, depending on the format

  • 0

I am reading in a csv file in Java and, depending on the format of the string on a given line, I have to do something different with it. The three different formats contained in the csv file are (using random numbers):

833
“79, 869”
“56-57, 568”

If it is just a single number (833), I want to add it to my ArrayList. If it is two numbers separated by a comma and surrounded by quotations (“79, 869)”, I want to parse out the first of the two numbers (79) and add it to the ArrayList. If it is three numbers surrounded by quotations (where the first two numbers are separated by a dash, and the third by a comma [“56-57, 568”], then I want to parse out the third number (568) and add it to the ArrayList.

I am having trouble using str.contains() to determine if the string on a given line contains a dash or not. Can anyone offer me some help? Here is what I have so far:

private static void getFile(String filePath) throws java.io.IOException {
    BufferedReader reader = new BufferedReader(new FileReader(filePath));
    String str;

    while ((str = reader.readLine()) != null) {

        if(str.endsWith("\"")){
            if (str.contains(charDash)){
                System.out.println(str);
            }
        }

    }

}

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-16T17:31:35+00:00Added an answer on May 16, 2026 at 5:31 pm

    I recommend using the version of indexOf that actually takes a char rather than a string, since this method is much faster. (It is a simple loop, without a nested loop.)

    I.e.

      if (str.indexOf('-')!=-1) {
          System.out.println(str);
       }
    

    (Note the single quotes, so this is a char, rather than a string.)

    But then you have to split the line and parse the individual values. At present, you are testing if the whole line ends with a quote, which is probably not what you want.

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

Sidebar

Related Questions

I'm reading a .csv file (I have no control of the format of the
I'm reading a .csv file that was created in Excel with the first line
I have a System.Data.DataTable which is populated by reading a CSV file which sets
Im having trouble reading from a CSV file final String DELIMITER = ,; Scanner
I am reading a CSV file with php. Many of the rows have a
I have been writing an implementation for reading a .csv data file into C#
I am reading a following CSV file in java and 1191196800.681 - !AIVDM,1,1,,,13aG?N0rh20E6sjN1J=9d4<00000,0*1D Here
I have a java program which reads in a csv file and converts it
Possible Duplicate: Reading csv file I have a comma delimited file: Some Text, More
In my iPhone app, I'm reading a csv file. The relevant line is 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.