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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:51:34+00:00 2026-05-22T01:51:34+00:00

just trying to sort out a small delimma I’m having here. Currently, I’m working

  • 0

just trying to sort out a small delimma I’m having here.

Currently, I’m working on an application that involves gathering a list of files into memory, to be deleted. Now, at this point, I thought that a java.io.File array would perhaps take up too much memory, since the list of Files in this context could be in the hundreds of possible entries.

Rather than eat excessive amounts of memory up with a list of File objects, I figured that gathering a list of filenames and storing them as a java.lang.String would be cheaper to memory. Now, here’s my problem: With the goal in mind that these files are to be deleted, which of these would be cheaper:

  1. Storing an array of File objects rather than String objects, and calling .delete(); on each one in a loop (too much memory used).
  2. Storing an array of String objects with the filenames, but for each iteration of the loop, create a new File object using the list of filenames, and call .delete(); on that file (which means each time the loop iterates, a new File object is created and destroyed–possibly too much processor power being used).

I want to make the program as fast as possible, so either approach has its merits, and I just want to see which of these has the least overhead. Thanks in advance!

  • 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-22T01:51:35+00:00Added an answer on May 22, 2026 at 1:51 am

    The java.io.File represents the filename information/metadata about an entry in the filesystem, it does not contain the contents of the file.

    In other words, code like new File("somelarge.txt") does not load the somelarge.txt file into memory.

    The only real data that each File object contains is a String path to the File (along with a transient int prefixLength) – consider the File class merely a wrapper around the String path that knows how to invoke all of the filesystem operations.

    The best choice here, barring some other requirements, is the code that is the easiest to read and conveys your intent the best.

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

Sidebar

Related Questions

I'm trying to figure out how to design a small application more elegantly, and
Just need help as I have been trying sort this out for ages now.
Just trying to get my head round Spring and figuring out how I wire
Just trying to canvas some opinions here. I was wondering how people go about
I've been trying to sort out the relationship between unique and index in Postgres
I'm having bit of a trouble trying to figure out how I would send
I'm am just trying to find out if there is any software available for
I'm currently, in C#, trying to figure out a way of finding a specific
Been round the web trying to sort this out, lots of info on pre
I am trying to get compass/sass/haml working using blueprint but not having any luck

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.