Im trying to create an ArrayList of LinkedLists.

I want to create an ArrayList of n elements. N is a number the user inputs. Each element of the ArrayList will have a LinkedList of size n. Once the linked lists are created I'm suppose to input data. Can someone please guide me through the process? I have provided what I have coded so far, please take a look and if something is wrong, I'd appreciate the feedback.
No description
3 Replies
JavaBot
JavaBot2mo ago
This post has been reserved for your question.
Hey @Lord.Yin! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
john
john2mo ago
As far as my understanding on your question. It seems your trying to create an ArrayList that contains N number of LinkedList objects, where each LinkedList has the same size of N. If my understanding is correct, then please do the following changes to your code. First create N number of Linkedlists and add those to the ArrayList. ArrayList<LinkedList<String>> arrayList = new ArrayList<>();
for (int i = 0; i < n; i++) {
LinkedList<String> mArray = new LinkedList<>();
arrayList.add(linkedList);
}
for (int i = 0; i < n; i++) {
LinkedList<String> mArray = new LinkedList<>();
arrayList.add(linkedList);
}
Then iterate the arrayList and add values using nested for loop
This message has been formatted automatically. You can disable this using /preferences.
JavaBot
JavaBot2mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server