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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:35:07+00:00 2026-05-26T09:35:07+00:00

So I have a file with arbitrary length with the following format: @HEADER1 //arbitrary

  • 0

So I have a file with arbitrary length with the following format:

@HEADER1
//arbitrary lines of data
@HEADER2
//arbitrary lines of data 
....

I will extract each and every header and save it in a Hashmap and then I will start parsing (sequentially) another file which is a superset of file1 e.g. has the following format:

@HEADER1
//arbitrary lines of data
//extended information
@HEADER2
//arbitrary lines of data
//extended information

So my idea is that I will built a hashmap of headers – going through file 1 once and then I will go through file 2 and on every header in it I will check if I have it in the hasmap if yes – I will do something with the data. So I was wondering whether this is an optimal solution – according to my back-of-the-head calculations this is going to be O(n) whereas if I had an arraylist and for every header in file 2 check whether it is also in the arraylist would have yield O(n^2) whereas N is the number of headers in the Arraylist – am I correct?

If there is an even more efficient way I’d be glad to head it.

EDIT:

I can’t guarantee that the order of headers is going to be the same only that what is in file1 should exist in file2. Also – I don’t really need to save anything for the VALUE, in this case I just need quick access to the key.

  • 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-05-26T09:35:07+00:00Added an answer on May 26, 2026 at 9:35 am

    A HashMap is a perfectly good choice here.

    So the next thing to think about is what that HashMap will store. The key could probably be a String and would be "@HEADER###" . But what about the data?

    You have a few options for the value in the HashMap. You could use a String, but take some time and think through what your data is. Is it the original lines of data AND the extended information you’re adding? Does that data represent something structured? Like a List of items?

    If you find yourself getting a String value from the map and doing additional processing consider replacing that String with a Class that better represents your data so you have something like HashMap<String, DoskiasData>.

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

Sidebar

Related Questions

I have a file in the following format: Data Data Data [Start] Data I
I have a program that reads arbitrary data from a file system and outputs
I have a WCF method that accepts arbitrary binary data which the service will
I have a file which is an XML representation of some data that is
I have 10 arbitrary letters and need to check the max length match from
I have a .svg file that has the following code: <svg version=1.1 x=0 y=0
I am attempting to have a file upload page that allows for an arbitrary
Suppose I have a text file with data separated by whitespace into columns. I
Lets say, I have the following text file: Listing 1: Endianess=little AddressModel=32 typedef struct{
I have a file mmap'd read-only/shared, with multiple threads/processes reading the data concurrently. A

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.