Question

HELP! please code in java: convert an arraylist of string with 250,000 words into 2d array.

HELP!

please code in java:

convert an arraylist of string with 250,000 words into 2d array.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

public class Convert_AL_TO_Array {

   public static void main(String[] args) {
       int n=250000;//just change the value of n to 250000
ArrayList<String> arrli = new ArrayList<String>(n);
//adding some dummy data in array list of strings
for (int i=1; i<=n; i++)
arrli.add(i+"");
//converting to 2d array
String arr2d[][]=new String[(int)Math.sqrt(n)][(int)Math.sqrt(n)];
for(int i=0;i<(int)Math.sqrt(n);i++)
{for(int j=0;j<(int)Math.sqrt(n);j++)
   {
   arr2d[i][j]=arrli.get(i*(int)Math.sqrt(n)+j);

   }
}
for(int i=0;i<(int)Math.sqrt(n);i++)
{for(int j=0;j<(int)Math.sqrt(n);j++)
   {
   System.out.print(arr2d[i][j]+"\t");
   }System.out.println();
}
   }

}

Add a comment
Know the answer?
Add Answer to:
HELP! please code in java: convert an arraylist of string with 250,000 words into 2d array.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT