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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:10:24+00:00 2026-06-12T20:10:24+00:00

I have a huge file with data (~8Gb / ~80 Million records). Every record

  • 0

I have a huge file with data (~8Gb / ~80 Million records). Every record has 6-8 attributes which are split by a single tab. I would like for starters to copy some given attributes in another file. So I would like a more elegant code than the above, for example if I want only the second and the last token from a total of 4:

StringTokenizer st = new StringTokenizer(line, "\t");
st.nextToken(); //get rid of the first token
System.out.println(st.nextToken()); //show me the second token
st.nextToken(); //get rid of the third token
System.out.println(st.nextToken()); //show me the fourth token

I’m reminding that it’s a huge file so I have to avoid any redundant if checks.

  • 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-12T20:10:26+00:00Added an answer on June 12, 2026 at 8:10 pm

    Your question got me wondering about performance. Lately I’ve been using Guava’s Splitter where possible, just because I dig the syntax. I’ve never measured performance, so I put together a quick test of four parsing styles. I put these together really quickly, so pardon mistakes in style and edge-case correctness. They’re based on the understanding that we’re only interested in the second and fourth items.

    What I found interesting is that the “homeGrown” (really crude code) solution is the fastest when parsing a 350MB tab-delimited text file (with four columns), ex:

    head test.txt 
    0   0   0   0
    1   2   3   4
    2   4   6   8
    3   6   9   12
    

    When operating over 350MB of data on my laptop, I got the following results:

    • homegrown: 2271ms
    • guavaSplit: 3367ms
    • regex: 7302ms
    • tokenize: 3466ms

    Given that, I think I’ll stick with Guava’s splitter for most work and consider custom code for larger data sets.

      public static List<String> tokenize(String line){
        List<String> result = Lists.newArrayList();
        StringTokenizer st = new StringTokenizer(line, "\t");
        st.nextToken(); //get rid of the first token
        result.add(st.nextToken()); //show me the second token
        st.nextToken(); //get rid of the third token
        result.add(st.nextToken()); //show me the fourth token
        return result;
      }
    
      static final Splitter splitter = Splitter.on('\t');
      public static List<String> guavaSplit(String line){
        List<String> result = Lists.newArrayList();
        int i=0;
        for(String str : splitter.split(line)){
          if(i==1 || i==3){
            result.add(str);
          }
          i++;
        }
        return result;
      }
    
      static final Pattern p = Pattern.compile("^(.*?)\\t(.*?)\\t(.*?)\\t(.*)$");
      public static List<String> regex(String line){
        List<String> result = null;
        Matcher m = p.matcher(line);
        if(m.find()){
          if(m.groupCount()>=4){
            result= Lists.newArrayList(m.group(2),m.group(4));
          }
        }
        return result;
      }
    
      public static List<String> homeGrown(String line){
        List<String> result = Lists.newArrayList();
        String subStr = line;
        int cnt = -1;
        int indx = subStr.indexOf('\t');
        while(++cnt < 4 && indx != -1){
          if(cnt==1||cnt==3){
            result.add(subStr.substring(0,indx));
          }
          subStr = subStr.substring(indx+1);
          indx = subStr.indexOf('\t');
        }
        if(cnt==1||cnt==3){
          result.add(subStr);
        }
        return result;
      }
    

    Note that all of these would likely be slower with proper bound checking and more elegant implementation.

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

Sidebar

Related Questions

I have a huge file, which has some missing rows. The data needs to
I have a huge a CSV file which I parse to store the data
I have to write huge data in text[csv] file. I used BufferedWriter to write
I have a huge file that has some lines that need to have a
I have a huge text file and I wanted to write a program which
I have a huge C file (~100k lines) which I need to be able
I have this very huge XML file of size 2.8GB. This is Polish Wikipedia's
I have a large data file, which is zipped, and approximately 20MB. When it's
In my app, I have a pretty huge datamodel and its .sqlite data file.
I have a set of flags which are part of a huge text data

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.