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

  • Home
  • SEARCH
  • 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 52061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:50:53+00:00 2026-05-10T16:50:53+00:00

I am trying to store more than 1 data item at a single index

  • 0

I am trying to store more than 1 data item at a single index in my linked-list. All of the examples in my textbook seem to illustrate adding only 1 piece of data per index. I’m assuming it is possible to add more?

For example, using the Collections API to store an integer I would do the following:

LinkedList <Integer>linky = new LinkedList<Integer>(); int num1 = 2, num2 = 22, num3 = 25, num4 = 1337; linky.add(num1); 

How would I go about adding num2, num3, and num4 to the same first index in the list? Thanks guys.

  • 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. 2026-05-10T16:50:53+00:00Added an answer on May 10, 2026 at 4:50 pm

    There seems to be a little confusion about how linked lists work. Essentially, a linked list is composed of nodes, each of which contains one datum (an object, which itself can contain several member variables, to be precise), and a link to the next node in the list (or a null pointer if there is no such next node). You can also have a doubly-linked list, where each node also has a pointer to the previous node in the list, to speed up certain kinds of access patterns.

    To add multiple ‘pieces of data’ to a single node sounds like adding several links off of one node, which turns your linked list into an N-ary tree.

    To add multiple pieces of data onto the end of the list, in the manner most commonly associated with a linked list, just do:

    LinkedList <Integer>linky = new LinkedList<Integer>(); int num1 = 2, num2 = 22, num3 = 25, num4 = 1337; linky.add(num1); linky.add(num2); linky.add(num3); linky.add(num4); 

    Alternately, if you want each node of the linked list to have several pieces of data

    These data should be packaged up into an object (by defining a class that has them all as member variables). For example:

    class GroupOfFourInts {    int myInt1;    int myInt2;    int myInt3;    int myInt4;     public GroupOfFourInts(int a, int b, int c, int d)    {      myInt1 = a; myInt2 = b; myInt3 = c; myInt4 = d;    } }  class someOtherClass {    public static void main(String[] args)   {     LinkedList<GroupOfFourInts> linky = new LinkedList<GroupOfFourInts>();     GroupOfFourInts group1 = new GroupOfFourInts(1,2,3,4);     GroupOfFourInts group2 = new GroupOfFourInts(1337,7331,2345,6789);     linky.add(group1);     linky.add(group2);   } } 

    Now, linky will have 2 nodes, each of which will contain 4 ints, myInt1, myInt2, myInt3, and myInt4.

    Note

    None of the above is specific to linked lists. This pattern should be used whenever you want to store a bunch of data together as a unit. You create a class that has member variables for every piece of data you want to be stored together, then create any Java Collections type (ArrayList, LinkedList, TreeList, …) of that type.

    Be sure that you want to use a linked list (as there’s no penalty in terms of programming difficulty in choosing an ArrayList or TreeList). This will depend on your data access pattern. Linked lists provide O(1) addition and deletion, but O(n) lookup, whereas ArrayLists provide O(1) lookup, but O(n) arbitrary add and delete. TreeLists provide O(log n) insertion, deletion, and lookup. The tradeoffs between these depend on the amount of data you have and how you’re going to be modifying and accessing the data structure.

    Of course, none of this matters if you’ll only have, say, <100 elements in your list 😉

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer So I kind of figured it out myself. If you… May 11, 2026 at 3:19 pm
  • added an answer Not sure where you're looking, but certainly on live.com I… May 11, 2026 at 3:19 pm
  • added an answer To get started with extracting ID3 tags in Python, there's… May 11, 2026 at 3:19 pm

Related Questions

I'm reading in a large text file with 1.4 million lines that is 24
I am trying to extract a table of values from an excel (2003) spreadsheet
I am working on a web API for the insurance industry and trying to
I doubt this is possible, but I was curious if you could have more

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.