Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Arrays of Class

  1. #1
    Junior Member
    Join Date
    Jul 2012
    My Mood
    Thanked 0 Times in 0 Posts

    Default Arrays of Class

    I am trying to create and array of a particular class, Ant, its actually an ArrayList and a multidimensional Array, see below. What I need to know is what do I need to add or change to do this.

    	public void initializeBoard()
    		ArrayList board[][] = new ArrayList[27][27];
    public class Ant {

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,405 Times in 2,358 Posts

    Default Re: Arrays of Class

    create and array of a particular class
    You create an array by using the [] notation with the data type:
    TheClassName[] anArrayOfTheClassName; // define array of TheClassName objects
    anArrayOfTheClassName = new TheClassName[5]; // assign a value to the array
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Class of arrays
    By Vessel06 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: April 9th, 2013, 08:46 PM
  2. Copying arrays from one class to another
    By hannah87 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 24th, 2013, 02:54 PM
  3. Do Class Casts Work With Arrays?
    By snowguy13 in forum Collections and Generics
    Replies: 8
    Last Post: February 23rd, 2012, 08:18 AM
  4. [SOLVED] Arrays being initialized from another class
    By Java Man 9000 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: January 11th, 2012, 04:34 PM
  5. Issue with setting up different class with arrays
    By D-COD3R in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 4th, 2011, 06:09 PM