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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:08:14+00:00 2026-06-18T21:08:14+00:00

I have a program containing a Linked List data structure to store custom TCP

  • 0

I have a program containing a Linked List data structure to store custom TCP packet.

Test program reads in a packet, adds it to the Linked List queue, and immediately prints the packet value (a timestamp value) for confirmation. This process is repeated 10 times in a while loop, so there are 10 packets in the Linked List queue.

Problem comes with a check on the queue values after all packets have been read in. The problem being that only the value of the last packet read in, is shown, despite the knowledge that there are 9 other packets with different values (supposedly) in the queue.

If someone could help me understand this seemingly black magic I would be most grateful.

public void readPackets() throws IOException {
    int counter = 1;

    while(counter < 10){
        packet = con.fillWIMPacket(packet);
        packetQueue.add(packet); 
        System.out.println("Packet " + counter + " added to Queue");
        System.out.println("Packet " + counter + " " + packet.toString());
        counter++;
    } 
}



public void printPacketValues(){

    System.out.println("Packet Queue size is " + packetQueue.size());


    for(int i = 0; i < packetQueue.size(); i++){
        System.out.println("Packet " + i + ": " + packetQueue.get(i));
    }

}

I should clarify that the println() methods of the first readPackets() is showing data in the correct order. However, the println() of printPacketValues() simply shows the value of the last packet 10 times..

  • 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-06-18T21:08:15+00:00Added an answer on June 18, 2026 at 9:08 pm
    while(counter < 10){
        packet = new PacketType(); //change here and try once.
        packet = con.fillWIMPacket(packet);
        packetQueue.add(packet); 
        System.out.println("Packet " + counter + " added to Queue");
        System.out.println("Packet " + counter + " " + packet.toString());
        counter++;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a program which reads a file containing multidimensional data (most commonly
I have a simple program which reads a large file containing few million rows,
I have a program with a TreeView list containing Nodes, and Nodes with Children.
I have a c++ program which generates many data files each of them containing
I have a C program containing a structure struct S{ int x; struct timeval
i have to write a program in C to read a file containing several
So right now I have a program containing a piece of code that looks
I have a java program using objects containing huge arrays of floats. Thing is
I have a CUDA program containing a host function and a device function Execute()
I have a thread which has an incoming job queue (a LinkedList containing job

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.