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

The Archive Base Latest Questions

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

I have a data file containing a combination of doubles and strings like this:

  • 0

I have a data file containing a combination of doubles and strings like this:

Rmax=2.3
Rmin=1.0

etc.

I’m using split() to cut out the = like this:

while ((strLine = br.readLine()) != null) {
            String phrase = strLine;                
            try {
                //splits to variable name, value
                String[] parsed = phrase.split("[=]");                      
                int parsed[0].toString() = parsed[1];

            } catch (PatternSyntaxException e) {
                System.out.println("Error: " + e.getMessage());
            }
        }

Now i’m trying to get the values initialized so that parsed[0] becomes the name of the integer and parsed[1] becomes the value. equivalent to the initializer
int name = value;

obviously the line

int parsed[0].toString() = parsed[1]; 

doesn’t work. how do i go about doing this?

  • 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-23T06:02:54+00:00Added an answer on May 23, 2026 at 6:02 am

    How about this

    Map<String, Double> map = new HashMap<String,Double>()
    while ((strLine = br.readLine()) != null) {
        //splits to variable name, value
        String[] parsed = phrase.split("=");
        String name = parsed[0];
        double value = Double.parseDouble(parsed[1]);
        map.put(name, value);
    }
    

    As has been mentioned you have to catch NumberFormatException and handle a missing ‘=’ depending on whether these are possible.

    If you know all possible fields you could use an enum for the field name.


    Instead of using a Map you could use an Object which you set via reflection.

    class Config {
        double Rmax;
        double Rmin;
        // add more fields here.
    }
    
    Config config = new Config;
        while ((strLine = br.readLine()) != null) {
        //splits to variable name, value
        String[] parsed = phrase.split("=");
        try {
           String name = parsed[0];
           double value = Double.parseDouble(parsed[1]);
           Config.class.getField(name).setDouble(value);
        } catch (Exception e) {
           // log exception.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file containing some user data it looks like this: 10333,,an.10,Kenyata,,Aaron,,,,,,,,,,
I have a .txt file containing data like this: 1,Rent1,Expense,16/02/2010,1,4000,4000 1,Car Loan1,Expense,16/02/2010,2,4500,9000 1,Flat Loan1,Expense,16/02/2010,2,4000,8000
I have a .txt file containing data like this: 0,Rent1,Expense,16/02/2010,1,4000,4000 0,Car Loan1,Expense,16/02/2010,2,4500,9000 0,Flat Loan1,Expense,16/02/2010,2,4000,8000
I have a file containing data like below: 88_NPDJ 565 789 3434 54454 98HGJDN
I have a file containing data that I'd like to monitor changes to, as
I have a file containing data in a single column .. I have to
I have a file containing lots of data put in a form similar to
I have a text file containing the data in following format 12345 Abdt3 hy45d
I have a .sql file from a MySQL dump containing tables, definitions and data
I have a data file that looks like the following example. I've added '%'

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.