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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:49:17+00:00 2026-06-15T03:49:17+00:00

LinkedList<DatagramPacket> queue = new LinkedList<DatagramPacket>(); for (int i = 0; i < queue.size(); i++)

  • 0
LinkedList<DatagramPacket> queue = new LinkedList<DatagramPacket>();

for (int i = 0; i < queue.size(); i++)
{
    System.out.println("1: This prints.");
    System.out.println("2: This doesn't: " + new String(queue.get(i).getData()));
    int start = (new String(queue.get(i).getData())).indexOf("\r\n") + "\r\n".length();
    data.concat(new String(queue.get(i).getData()).substring(start));
}

We’re trying to take all the data from queue, the list of packets, and put them all into one string.

But whenever it gets to the 2nd println (which is the same as the line below it) the program hangs and doesn’t do anything.

Without the getData() the print works. eg.

System.out.printlin("2: This doesn't: " +  new String(queue.get(i)));

Also, whenever I add a packet to the queue, I immediately print the last packet in the queue, and that works.

public void addPacket(DatagramPacket additional)
{
    queue.add(additional);
    System.out.println("1: " + new String(queue.getLast().getData()));
}
  • 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-15T03:49:18+00:00Added an answer on June 15, 2026 at 3:49 am

    I’m not sure about the DatagramPacket class, but this certainly fixes some performance problems related to String manipulation and LinkedList.get. It might just be that your program runs really slowly?

    StringBuilder dataBuilder = new StringBuilder(); 
    Iterator<DatagramPacket> queueIter = queue.iterator();
    while(queueIter.hasNext()) {
      DatagramPacket next = queueIter.next();
      System.out.println("1: This prints.");
      System.out.println("2: This doesn't: " + new String(next.getData()));
      int start = (new String(next.getData())).indexOf("\r\n") + "\r\n".length();
      dataBuilder.append(new String(next.getData()).substring(start));
    }
    data = dataBuilder.toString();
    

    What if you tried this:

    public class Foo {
      // instead of LinkedList<DatagramPacket>
      public LinkedList<String> queue = new LinkedList<String>(); 
      public void addPacket(DatagramPacket additional) {
          queue.add(new String(additional.getData()));
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try: LinkedList<String> stringList = new LinkedList<String>(); I get the following compilation error:
I need to convert LinkedList<String> to LinkedList<int> using Linq ? What is the best
defined variable: LinkedList list1=new LinkedList(); Object get() in list1 obtains a node of list1
Let's say I have the following: LinkedList<int> list1 = new LinkedList<int>(); LinkedList<int> list2 =
Superclass: public class CwDB{ protected LinkedList<Entry> dict = null; public CwDB(String filename){ this.dict =
I have two LinkedList objects that are always of the same size. I want
Why Methode LinkedList.contains() runs quickly than such implementation: for (String s : list) if
I have a linked list samples : protected LinkedList<RawDataset> samples = new LinkedList<RawDataset>(); I'm
int LinkedList::DoStuff() { Node *Current = next_; while ( Current != NULL ) {
When using Java LinkedList how do you find out the element's next or previous

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.