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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:55:16+00:00 2026-06-13T01:55:16+00:00

Say I had a String: Hello! I have to do all this: Convert string

  • 0

Say I had a String: Hello! I have to do all this:

  1. Convert string into byte array
  2. Send byte array
  3. Convert it back to a string (for later use)

This is my code…

//Sender
String send = "Hello!";
byte[] data = send.getBytes();
DatagramPacket packetOut = new DatagramPacket(data, data.length); //send blah blah

//Receiver
//blah blah receive it
String receive = new String(packetIn.getData()); //convert it back

What’s a quick and elegant way to do this for an array of integers?

  • 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-13T01:55:17+00:00Added an answer on June 13, 2026 at 1:55 am

    For an int[] you can serialize using ObjectOutputStream but a faster way might be to use a ByteBuffer.

    public static byte[] intsToBytes(int[] ints) {
        ByteBuffer bb = ByteBuffer.allocate(ints.length * 4);
        IntBuffer ib = bb.asIntBuffer();
        for (int i : ints) ib.put(i);
        return bb.array();
    }
    
    public static int[] bytesToInts(byte[] bytes) {
        int[] ints = new int[bytes.length / 4];
        ByteBuffer.wrap(bytes).asIntBuffer().get(ints);
        return ints;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say if I had a string which had this text/html stored in it: Hello.
This seems stupid - must be me! Say I had a string filter[size] =
Let's say you had a string test = 'wow, hello, how, are, you, doing'
Let's say I had a string like this: string source = Today is friday!
Say I had a function such as this one procedure TMyObject.DoSomething(text: string); begin //
Can anyone suggest how I would do this: Say if I had the string
Say you had this: class A { public string name; } And then you
Say I had String s = This is a loooooooooooooooong string; . Now say
Hello everyone I have this problem, I had to make a AsyncTask because the
So lets say I had a string that was <html> <head><title>301 Moved Permanently</title><head> and

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.