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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:47:53+00:00 2026-06-06T01:47:53+00:00

I have the following static method that prints the data imported from a 40.000

  • 0

I have the following static method that prints the data imported from a 40.000 lines .xls spreadsheet.

Now, it takes about 27 seconds to print the data in the console and the memory consumption is huge.

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;

public static void printSheetData(List<List<HSSFCell>> sheetData) {
    for (int i = 0; i < sheetData.size(); i++) {
        List<HSSFCell> list = (List<HSSFCell>) sheetData.get(i);
        for (int j = 0; j < list.size(); j++) {
            HSSFCell cell = (HSSFCell) list.get(j);
            System.out.print(cell.toString());
            if (j < list.size() - 1) {
                System.out.print(", ");
            }
        }
        System.out.println("");
    }
}

Disclaimer: I know, I know large data belong to a database, don’t print output in the console, premature optimization is the root of all evils…

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

    Rather than printing out each line one at a time, have you tried using a StringBuilder to create your large String, and then either printing that at one shot, or after so many lines have been added? You would be using the StringBuilder as a kind of buffer.

    e.g.,

    public static void printSheetData(List<List<HSSFCell>> sheetData) {
        StringBuilder strBuilder = new StringBuilder();
        for (int i = 0; i < sheetData.size(); i++) {
            List<HSSFCell> list = (List<HSSFCell>) sheetData.get(i);
            for (int j = 0; j < list.size(); j++) {
                HSSFCell cell = (HSSFCell) list.get(j);
                // System.out.print(cell.toString());
                strBuilder.append(cell.toString());
                if (j < list.size() - 1) {
                    // System.out.print(", ");
                    strBuilder.append(", ");
                }
            }
            // System.out.println("");
            strBuilder.append("\n");
    
            // consider testing strBuilder size here and printing it out if
            // it is greater than some pre-set, then re-initializing the 
            // strBuilder variable.
        }
        System.out.println(strBuilder.toString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That is, I have a method such as the following: public static int CreateTaskGroup(string
I have the following method: static double NewtonMethodModified(Func<double, double> f, double x0, double h)
I have the following method: public static T ExecuteScalar<T>( string query, SqlConnection connection, params
I have the following method public static void SerializeToXMLFile(Object obj,Type type, string fileName) {
On my front end, I have following functions: method to encrypt: public static string
I have the following method declaration: public static bool SerializeObject<T>(string filename, T objectToSerialize){ I
I have the following method in an App_Code/Globals.cs file: public static XmlDataSource getXmlSourceFromOrgid(int orgid)
I have a general Java method with the following method signature: private static ResultSet
I have the following method that loads in a blank template image, draws the
Here are the directions: Implement the following method so that it prints all even-valued

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.