Dave's Brain

Browse - Programming Tips - How do I initialize an array of a class?

Date: 2012sep22
Language: Java	
Keywords: init

Q.  How do I initialize an array of a class?

A.

class Person { String first; String last; Person(final String first, final String last) { this.first = first; this.last = last; } } Person[] people = new Person[] { new Person("John", "Smith"), new Person("Steve", "Jobs"), new Person("Bill", "Gates"), };

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.