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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:46:53+00:00 2026-06-14T19:46:53+00:00

having Obj class which in his constructor has System.out.println(Hello world!) ; I create an

  • 0

having Obj class which in his constructor has System.out.println("Hello world!") ;

I create an array of this class using – Obj[] objArray = new Obj[10] ; and nothing printed , means – no instance of Obj has been called . Is there any way to create such array ,but with instances , beyond create them in for loop ?

  • 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-14T19:46:55+00:00Added an answer on June 14, 2026 at 7:46 pm

    Well, since you want to know a way apart from using a for loop, you can do this: –

    Obj[] objArray = {new Obj(), new Obj(), new Obj()};
    

    What happens here is, you are initializing your array reference directly with array elements.
    Now the type of actual array object is inferred from type of array reference on the LHS.

    So, with that declaration, an array of size 3 (in the above case) is created, with each index in the array initialized with the instance of Obj class in the given order.


    A better way that I would suggest is to use an ArrayList, in which case, you have double-braces initialization to initialize your List without for loop. And plus with an added advantage that you can anytime add new elements to it. As it dynamically increasing array.

    List<Object> list = new ArrayList<Object>() {
        {
            add(new Obj());
            add(new Obj());
            add(new Obj());
        }
    };  // Note the semi-colon here.
    
    list.add(new Obj());  // Add another element here.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i`m having this structure(array) which i want to fill with Class objects. What is
i am studying apple obj-c guide and i am having problem understanding class types,
Consider the following constructor for the class Foo (which for the sake of clarity
I want the constructor to create a dynamic array and assign arguments passed to
Some Obj-C instruction use variables in an extension vs having them as an ivar.
I have the following data: [{class:test,description:o hai,example:a,banana:b}] As this JSON data is already in
I have a design issue which I can't just figure out how to solve.
I am calling a function test() on an anchor tag like this:- <a class=link
I'm new to obj-c/iOS and I'm having trouble understanding conceptually at least viewControllers. I've
I have found other examples of people having this problem but have had no

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.