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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:31:22+00:00 2026-05-20T07:31:22+00:00

I want to convert a List to a List so that each object on

  • 0

I want to convert a List to a List so that each object on my new list includes the first element of each String[].

Do you know if this is possible to do in java?

for example:

public List<String[]> readFile(){
  String[]array1={"A","1.3","2.4","2.3"};
  String[]array2={"B","1.43","3.4","2.8"};
  String[]array3={"C","5.23","2.45","2.9"};

  List<String[]>ReadFile= new ArrayList<String[]>();

  ReadFile.add(array1);
  ReadFile.add(array2);
  ReadFile.add(array3);

  return ReadFile;
}

Now I want a method which will take the List ReadFile from above to somehow split the arrays of strings into an ID which will be the first element “A”, “B”, “C” and another part which would be the string array of numbers which I will put through another method to convert numbers from String to type Double. I have already got the method to convert to double but I need to be able to keep track of the ID field because the ID field will be used to identify the array of numbers.

A friend suggested that I create an Object where each objects has one part as a String ID and the other part as an array. That is the part which I do not know how to do.

Can anybody help please?
below is the method declaration which I believe I should have so the return type will be List where each array has been converted to an Object with two parts.

public List<Object> CreateObject(List<String[]>ReadFile){

}

Thanks,
Jetnori.

Hi all, Thank you for taking your time to help.
I can see the benefit of using HashTables. I am as of now trying to implement it. I know i might be sidetracking a little but just to explain what I am trying to do:
In my project I have CSV file with data about gene expression levels. The method that I use from OpenCSV to read the file returns a List(String[]) where each String[] is one row in the file. The first element of each row is variable name (recA, ybjE etc). The rest of the row will be numbers data related to that variable. I want to calculate Pearson’s correlation between each of the number arrays. The method which I have got implemented already does that for me but the problem that I have now is that I had to remove the string values from my arrays before I could convert to double by iterating over the array. After I have managed to calculate the correlation between each array of doubles by still keeping the ID linked to the row, I want to be able to draw an undirected node graph between the genes that have a correlation higher than a threshold which I will set (for example correlation higher than 0.80). I don’t know if i am biting more than i can chew but I have 30 days to do it and I believe that with the help of people like you guys I will get through it.
Sorry for going on for a bit.
thanks,
Jetnori.

  • 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-20T07:31:22+00:00Added an answer on May 20, 2026 at 7:31 am

    I agree with the answer Alb provided, however this is what your friend has suggested, first you need a class to represent the data. I have included a constructor that parses the data and one that accepts already parsed data, depending on how you like to think of things.

    public class NumberList {
      private double[] numbers;
      private String key;
    
      public NumberList(Strig key, double[] numbers){
        this.ley = key;
        this.numbers = numbers;
      }
    
      public NumberList(String[] inputList) {
        key = inputList[0];
        numbers = new double[inputList.length-1];
        for(int i=1;i<inputList.length;i++){
          numers[i-1] = Double.parseDouble(inputList[i]);
        }
      }
    
      public String getKey() {
        return key;
      }
    
      public double[] getNumbers() { 
        return numbers;
      }
    }
    

    Then you need your function to generate the list:

    public List<NumberList> CreateObject(List<String[]> ReadFile){
      ArrayList<NumberList> returnList = new ArrayList<NumberList>(ReadFile.size());
      for (String[] input : ReadFile) {
        returnList.add(new NumberList(input));
      }
      return returnList;
    }
    

    Note this uses the constructor that parses the data, if you use the other constructor then the “CreateObject” function would need to include the parsing logic.

    Finally on a side note the standard convention in java is that the only thing that is capitalized are class names and final static fields (which appear in all caps sepearted by underscores), so conventionally the method signature would be:

    public List<NumberList> createObject(List<String[]> readFile){
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert scheme code to Haskell code. For that, I want
My page has a chart that is set up to display data that is
Using django-social-auth to grab user data from facebook, it is returning a list of
In SharePoint it has a nasty habit of using nested tables everywhere. I want
I'm working on a CMS, and I'm looking for a way to convert a
I want the user to submit a form and get a pdf back. Like
what I want to do is as following: I have a set of Drawables
Let's say I have a List of strings. In addition to the list, I
I have a ASP.NET MVC 3 application, using Entity Framework 4 to handle Data
Would OCR Software be able to reliably translate an image such as the following

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.