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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:16:28+00:00 2026-06-10T07:16:28+00:00

(No networking knowledge required whatsoever. This is purely String and Lists). Say I have

  • 0

(No networking knowledge required whatsoever. This is purely String and Lists).

Say I have a function in place, one that accepts a list of String IPv4 dotted address, and sorts them in ascending order. (Not alphabetical, true ip long format sorting). Let’s call this:

public static ArrayList<String> sortListOfIpv4s(ArrayList<String> unsortedIPv4s);

This function already works correctly. Given an input:

192.168.1.1, 8.8.8.8, 4.5.6.7, 244.244.244.244, 146.144.111.6

It will output the list:

4.5.6.7, 8.8.8.8, 146.144.111.6, 192.168.1.1, 244.244.244.244

(Let’s not get into a debate on whether it should modify the list in place or return a new list. It just returns a new list. Also, the function cannot be modified because of numerous reasons.)

However, my input list looks like this:

e192.168.1.1, f8.8.8.8, e4.5.6.7, f244.244.244.244, e146.144.111.6

When I remove the prefixes (only one of e or f, NOT NECESSARILY alternating) and create a clean array to pass to the sorting function, I lose the prefix information. What I would like is an output of the type:

e4.5.6.7, f8.8.8.8, e146.144.111.6, e192.168.1.1, f244.244.244.244

Basically, prior to sorting, whatever prefix was present for each element in the unsorted list, the same prefix needs to be added back to the elements in the sorted list.

Caveats:

  • An IP Address can repeat in the original list, a maximum of two times
  • When repeating twice, each of the two elements will have the same prefix, guaranteed
  • Sorting algorithm will not remove duplicates.

A little algorithmic help please? (Remember, we already have a function that can sort clean IPv4 String arraylists).

  • 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-10T07:16:29+00:00Added an answer on June 10, 2026 at 7:16 am

    Don’t remove the prefixes prior to passing it to the sorting function. Instead, in the sortListOfIpv4s method, always compare Strings using s.substring(1), which will give you the entire string without the prefix, and add s to the resulting sorted array.

    If sortListOfIpv4s is a black box and you are required to pass the prefix-free Strings, then you could cache the prefixes beforehand in a Map from prefix-free IP -> prefix:

    Map<String, String> prefixMap = new HashMap<String, String>();
    for (String ip : unsortedIPv4s) {
      prefixMap.put(ip.substring(1), ip.substring(0, 1));
    }
    

    Then sort and recover the prefixes from the Map:

    List<String> sortedIPV4s = sortListOfIpv4s(unsortedIPv4s);
    for (String ip : sortedIPV4s) {
      String prefix = prefixMap.get(ip);
      String originalIp = prefix + ip;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a networking framework that I am writing (Trying to implement reliable layer
I have a very dynamic (social networking) site running smarty that I want to
In a networking project I have multiple objects that each have a message queue
I'm learning networking in C#, and I realized that I'm completely dependent on the
I'm designing a networking framework which uses WSAEventSelect for asynchronous operations. I spawn one
I am learning Computer Networking this semester, on which I find it quite interesting
I have some networking code which connects to a multicast address but disconnects after
I am implementing some networking stuff in our project. It has been decided that
Scenario Does anyone have any good examples of peer-to-peer (p2p) networking in C++ using
in networking what type of socket should i use to guarantee that the receiving

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.