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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:37:39+00:00 2026-06-16T23:37:39+00:00

I have a program in java that I wrote to return a table of

  • 0

I have a program in java that I wrote to return a table of values. Later on as the functions of this program grew I found that I would like to access a variable within the method that isn’t returned but I am not sure the best way to go about it. I know that you cannot return more than one value but how would I go about accessing this variable without a major overhaul?
here is a simplified version of my code:

public class Reader {
    public String[][] fluidigmReader(String cllmp) throws IOException {
        //read in a file
        while ((inpt = br.readLine()) != null) {
            if (!inpt.equals("Calls")) {
                continue;
            }
            break;
        }
        br.readLine();
        inpt = br.readLine();
        //set up parse parse parameters and parse
        prse = inpt.split(dlmcma, -1);
        while ((inpt = br.readLine()) != null) {
            buffed.add(inpt);
        }
        int lncnt = 0;
        String tbl[][] = new String[buffed.size()][rssnps.size()];
        for (int s = 0; s < buffed.size(); s++) {
            prse = buffed.get(s).split(dlmcma);
            //turns out I want this smpls ArrayList elsewhere
            smpls.add(prse[1]);
//making the table to search through
            for (int m = 0; m < prse.length; m++) {
                tbl[lncnt][m] = prse[m];
            }
            lncnt++;
        }
        //but I return just the tbl here
        return tbl;
    }

Can anyone recommend a way to use smpls in another class without returning it? Is this perhaps when you use a get/set sort of setup?
Sorry if this seems like an obvious question, I am still new to the world of modular programming

  • 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-16T23:37:40+00:00Added an answer on June 16, 2026 at 11:37 pm

    Right now you have this tbl variable. Wrap it in a class and add the list to the class.

    class TableWrapper {
        // default accessing for illustrative purposes - 
        // setters and getters are a good idea
        String[][] table;
        List<String> samples;
    
        TableWrapper(String[][] table, List<String> samples) {
            this.table = table;
            this.samples = samples;
        }
    }
    

    Then refactor your method to return the wrapper object.

    public TableWrapper fluidigmReader(String cllmp) throws IOException {
        // your code here
        String tbl[][] = new String[buffed.size()][rssnps.size()];
        TableWrapper tw = new TableWrapper(tbl,smpls);
        // more of your code
        return tw;
    }  
    

    Then later in your code where you were going

    String[][] tbl = fluidigmReader(cllmp);
    

    You instead go

    TableWrapper tw = fluidigmReader(cllmp);
    String[][] tbl = tw.table;
    List<String> smpls = tw.samples;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java program that is running in the background(Windows). I would like
So I have this Java program that I use to munch through several terabytes
I have this java program where I transform with TransformerFactory a XML string that
I have to write a Java program that tells what coins to give out
I have a java program that performs 5 different tasks. When I run the
I have a Java program that runs many small simulations. It runs a genetic
I have a java program that will work with a variety of Java Beans.
I have a Java program that executes from Spring Qquartz every 20 seconds. Sometimes
I have a Java program that is launched by a batch file with a
I have a Java program that generates Java classes for my application. Basically it

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.