Arrays: Storing class objects in Array as data items : Generic Collections « Generics « Java Tutorial





class Person {
  private String lastName;
  private String firstName;

  private int age;

  public Person(String last, String first, int a) {
    lastName = last;
    firstName = first;
    age = a;
  }

  public String toString() {
    return "Last name: " + lastName + " First name: " + firstName + " Age: " + age;
  }

  public String getLast() {
    return lastName;
  }
}

public class MainClass {
  public static void main(String[] args) {
    Person[] persons = new Person[10];

    for(int i=0;i<persons.length;i++){
      persons[i] = new Person("A","B",10);
    }
    
    for(Person p: persons){
      System.out.println(p.getLast());
      
    }
  }
}
A
A
A
A
A
A
A
A
A
A










12.2.Generic Collections
12.2.1.Generics and Collections: ArrayList
12.2.2.Arrays: Storing class objects in Array as data items
12.2.3.Using Generic Comparable interface
12.2.4.A generic first-in, first-out bounded collection of objects
12.2.5.A list declared to hold objects of a type T can also hold objects that extend from T.
12.2.6.Utilities for generic ArrayList
12.2.7.Your own tree with generic user object
12.2.8.Generic to list
12.2.9.Create a typesafe copy of a raw list.
12.2.10.Create a typesafe copy of a raw map.
12.2.11.Create a typesafe filter of an unchecked iterator.
12.2.12.Create a typesafe view over an underlying raw set.
12.2.13.Create a typesafe view over an underlying raw map.
12.2.14.Create a typesafe filter of an unchecked enumeration.