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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:40:36+00:00 2026-05-28T03:40:36+00:00

I am programming for a memory-constrained device. Hence, I want to avoid allocating any

  • 0

I am programming for a memory-constrained device. Hence, I want to avoid allocating any memory.

Obviously, iterating across sets, lists, etc will allocate an iterator and thus allocate memory. So this should be avoided.

Does the native java syntax for iterating across arrays allocate memory?

Object[] array = getArray()
for(Object elem: array){
  //do something
}

(I suppose I could always use the old-fashioned for loop with an index variable.)

  • 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-28T03:40:36+00:00Added an answer on May 28, 2026 at 3:40 am

    Nope. In all compilers that I have checked this is implemented by a for loop (0..array.lengh-1).

    Note that Java arrays do not implement Iterable. This can be seen, for instance, by the following code:

    Object[] arr = new String[100];
    Iterable<?> iter = arr;  // Error: 'Type mismatch: 
                             //         cannot convert from Object[] to Iterable<?>'
    

    [UPDATE]

    And here is the definite source: https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.14.2

    A for loop such as

    for ( VariableModifiersopt Type Identifier: Expression) Statement
    

    has the following meaning when Expression is an array of type T[]:

    T[] a = Expression;
    for (int i = 0; i < a.length; i++) {
           VariableModifiersopt Type Identifier = a[i];
           Statement
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any really low level programming language that can get access the memory
Based on a Memory Efficient Programming question on StackOverflow ..... I want to know
In the Memory Management Programming Guide for Cocoa Apple talks about Top-Level Objects. They
Herlihy and Shavit's book ( The Art of Multiprocessor Programming ) solution to memory
I'm programming an application for a 32 bit processor with limited memory (512k flash,
I have just been getting into low level programming (reading/writing to memory that sort
I am learning parallel programming by myself. I wonder if distributed memory is always
I'm working on a custom mark-release style memory allocator for the D programming language
The Cocoa Memory Management Programming Guide document says: You take ownership of an object
The function which creates shared memory in *inux programming takes a key as one

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.