Fixed length: Once an array is created, we cannot change its size. So consider using arrays when the numbers of elements are known and fixed. Otherwise, you should consider using another dynamic container such as ArrayList.

It’s very fast to access any elements in an array (by index of the elements) in constant time: accessing the 1st element takes same time as accessing the last element. So performance is another factor when choosing arrays.

An array can hold primitives or objects, stores values of the primitives.

An array of objects stores only the references to the objects.

In Java, the position of an element is specified by index which is zero-based. That means the first element is at index 0, the second element at index 1, and so on.

An array itself is actually an object.

//Hack 1
int[] arrayOne = {2, 4, 6, 8, 10, 12};
for (int i = 0; i < arrayOne.length; i+=2) { // if smaller than array length then increments by 2
    System.out.println(arrayOne[i]); //prints array
}
//Hack 2
int[] myNumbers = new int[] {4, 5, 3, 1, 2}; //jumbled array
int i = 0;
int min = 0;
public void arraySorter(int[] array) {
    for (int i = 1; i < array.length+1; i++) { //sorts in order
        for (int j = 0; j < array.length; j++) {
            if (i == array[j]) {
                System.out.println(i);
            }
        }
    }
}
 
arraySorter(myNumbers);
public void addMembers(String[] names, int graduationYear) {
    //string that includes the names - 1st parameter
    //int that contains the grad year - 2nd parameter
    
    for (int i = 0; i<names.length; i++) { //repeats for as many letters are in the name
      memberList.add(new Member(names[i], graduationYear, true));
      //adds the names and grad year to the member list for each member

      return memberList; //this could possibly be names
    }
  }
//Hack 1
int[] arrayOne = {2, 4, 6, 8, 10, 12};
for (int i = 0; i < arrayOne.length; i+=2) { // if smaller than array length then increments by 2
    System.out.println(arrayOne[i]); //prints array
}
2
6
10
//Hack 2
int[] myNumbers = new int[] {4, 5, 3, 1, 2}; //jumbled array
int i = 0;
int min = 0;
public void arraySorter(int[] array) {
    for (int i = 1; i < array.length+1; i++) { //sorts in order
        for (int j = 0; j < array.length; j++) {
            if (i == array[j]) {
                System.out.println(i);
            }
        }
    }
}
 
arraySorter(myNumbers);
1
2
3
4
5

a) Write the ClubMembers method addMembers, which takes two parameters. The first parameter is a String array containing the names of new club members to be added. The second parameter is the graduation year of all the new club members. The method adds the new members to the memberList instance variable. The names can be added in any order. All members added are initially in good standing and share the same graduation year, gradYear.

public void addMembers(String[] names, int graduationYear) {
    //string that includes the names - 1st parameter
    //int that contains the grad year - 2nd parameter
    
    for (int i = 0; i<names.length; i++) { //repeats for as many letters are in the name
      memberList.add(new Member(names[i], graduationYear, true));
      //adds the names and grad year to the member list for each member

      return memberList; //this could possibly be names
    }
  }