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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:51:11+00:00 2026-05-30T00:51:11+00:00

I have a requirement wherein i should write a method of type String[] and

  • 0

I have a requirement wherein i should write a method of type String[] and return the same.But the implementation that i have, uses and returns List<List<String>>.Also the List<List<String>> gets and returns values from the database and the values are not known prior to add them to the String[] directly.The list can also be of a huge size to accomodate it in an String[] . How to get this conversion done.

  • 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-30T00:51:12+00:00Added an answer on May 30, 2026 at 12:51 am

    Take a look at this code:

    public static String[] myMethod(ArrayList<ArrayList<String>> list) 
    {
        int dim1 = list.size(); 
        int total=0;
        for(int i=0; i< dim1; i++)
            total += list.get(i).size();
    
        String[] result = new String[total];        
    
        int index = 0;
        for(int i=0; i<dim1; i++)
        {
            int dim2 = list.get(i).size();
            for(int j=0; j<dim2; j++)
            {
                result[index] = list.get(i).get(j);
                index++;
            }
        }
    
        return result;
    }
    

    Run this test code:

    public static void main(String[] args)
        {
            ArrayList<String> list1 = new ArrayList<String>();
            ArrayList<String> list2 = new ArrayList<String>();
            ArrayList<String> list3 = new ArrayList<String>();
    
            list1.add("first of first");
            list1.add("second of first");
            list1.add("third of first");
    
            list2.add("first of second");
    
            list3.add("first of third");
            list3.add("second of third");
    
            ArrayList<ArrayList<String>> superList = new ArrayList<ArrayList<String>>();
            superList.add(list1);
            superList.add(list2);
            superList.add(list3);
    
            String[] output = myMethod(superList);
    
            for(int i=0; i<output.length; i++)
                System.out.println(output[i]);                  
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement wherein I have to change the text of the return
I have a requirement wherein I need to display on a User form, a
In our project we have requirement that, after receiving sms message from third party
I am new to extension development, I have a requirement wherein I need to
I have a requirement in JasperReports wherein I need to display the field based
We have a requirement, wherein the administrative user needs to proxy in as a
I have a requirement wherein I have a bunch of about 10 aspx pages.The
I have a requirement wherein I need to display a list of employees and
I have a requirement wherein I have to buffer a lot of data (in
I have a pretty usual requirement with procmail but I am unable to get

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.