|
In Grade 11, you learned to use single dimension arrays.
Bouncing Ball Demo - Extended with ArrayLists and OOP.
Arrays can be n-dimensional. However we'll limit ourselves to 2-dimensional arrays.
Declaring a 2-dimensional array looks like:
double a[ ][ ] = new double[5][5]; // coefficients of the equations
Yes, you use the [ ] brackets
Remember that in Java, arrays are ZERO-INDEXED - the first location is [0][0]
When an array is created, it has the following default assigned values in each location.
boolean : false
int : 0
chr: null
double : 0.0
String : null
User Defined Type : null
Think of a 2-d array like a table of rows and columns. (ex. an Excel Spreadsheet). You reference a given cell by using the index for the row and column you wish to access.
ex. curValue = table[i][j]; // where i and j are integers
To set a location in an array, the operation looks like:
climateData[i][j]= todaysTempererature;
Make a fresh project and try this demo - Question: What would happen if you swapped row,col indices in last for loop?
Application of 2-Dimensional Arrays - Solving Systems of Equations - Complete for homework
Machine Learning - Building a Colour Identification Model - Arduino too!
---------------------------------------------------------------------------------------------------------
Array Lists
Introduction to ArrayLists - Michael Fudge Video
Nice Summary of ArrayList Concepts and operations
REMEMBER to 'import java.util.ArrayList;' in your projects.
Practice: 1. Create an arrayList for Marks of type 'double'. Add in 5 marks, at least one of which is 30. Then do an operation to remove the 30 mark
insert a mark 82 in the arrayList
2. Create an arrayList of animals (string object type). Then add some animal names include 'elephant'. Then insert elephant at the end of the arrayList
Now search for elephant using indexof and lastindexof. Store the results of those searches in an int variable and then remove those entries using
the .remove method for that index variable. Print out your list after the operations are complete.
NOTE: If you want to remove an nth Integer or Double element from an array list, use
list.remove(Integer.valueOf(2));
This is because by default, the types are not int primitives but Integer objects. They're firstly look at like strings.
So doing a force-casting of the element as an Integer, means you're looking for the number 2 value in the ArrayList, not ArrayList item 2.
Passing An ArrayList to a Method that returns an ArrayList
---------------------------------------------------------------------------------------------------------
On the Final Exam, it's fair game for you to be expected to write the FULL Java code for any and/or all of the:
-Bubble Sort, Selection Sort, Insertion Sort
-Binary Search
to solve a specific problem
Sorting - Simplified
Selection Sort - Pseudocode and Walkthrough
Bubble Sort - Pseudocode and Walkthrough
Insertion Sort - Pseudocode and Walkthrough
Sorting Algorithms
Video demonstration of Bubble Sort, Shell Sort and Quicksort
A Sorting Race!
Overview of the Quick Sort Algorithm
Sorting Summary Article with Animations
A Comparative Sorting Algorithm GIF
Searching Algorithms
Binary Search - Pseudocode and Walkthrough
Binary Searching for a Date - Flamenco Style!
Sorting and Searching Practice - do this...no..REALLY! DO THIS!!! TESTABLE MATERIAL
Passing An ArrayList to a Method that returns an ArrayList
Big 'O' Notation - Time Efficiency of Algorithms
Lecture - Big O and Comparable Interface concepts
Tutorial - The Comparable Interface
Article on Big 'O' Notation
A Gentle Explanation of Logarithmic TIme Complexity
What the current system clock time? (for analyzing execution time for an algorithm)
long startTime = System.currentTimeMillis();
.... your algorithm
long duration - System.currentTimeMillis - startTime;
System.out.println(duration);
Bouncing Ball Demo - Extended with ArrayLists and OOP.
Arrays can be n-dimensional. However we'll limit ourselves to 2-dimensional arrays.
Declaring a 2-dimensional array looks like:
double a[ ][ ] = new double[5][5]; // coefficients of the equations
Yes, you use the [ ] brackets
Remember that in Java, arrays are ZERO-INDEXED - the first location is [0][0]
When an array is created, it has the following default assigned values in each location.
boolean : false
int : 0
chr: null
double : 0.0
String : null
User Defined Type : null
Think of a 2-d array like a table of rows and columns. (ex. an Excel Spreadsheet). You reference a given cell by using the index for the row and column you wish to access.
ex. curValue = table[i][j]; // where i and j are integers
To set a location in an array, the operation looks like:
climateData[i][j]= todaysTempererature;
Make a fresh project and try this demo - Question: What would happen if you swapped row,col indices in last for loop?
Application of 2-Dimensional Arrays - Solving Systems of Equations - Complete for homework
Machine Learning - Building a Colour Identification Model - Arduino too!
---------------------------------------------------------------------------------------------------------
Array Lists
Introduction to ArrayLists - Michael Fudge Video
Nice Summary of ArrayList Concepts and operations
REMEMBER to 'import java.util.ArrayList;' in your projects.
Practice: 1. Create an arrayList for Marks of type 'double'. Add in 5 marks, at least one of which is 30. Then do an operation to remove the 30 mark
insert a mark 82 in the arrayList
2. Create an arrayList of animals (string object type). Then add some animal names include 'elephant'. Then insert elephant at the end of the arrayList
Now search for elephant using indexof and lastindexof. Store the results of those searches in an int variable and then remove those entries using
the .remove method for that index variable. Print out your list after the operations are complete.
NOTE: If you want to remove an nth Integer or Double element from an array list, use
list.remove(Integer.valueOf(2));
This is because by default, the types are not int primitives but Integer objects. They're firstly look at like strings.
So doing a force-casting of the element as an Integer, means you're looking for the number 2 value in the ArrayList, not ArrayList item 2.
Passing An ArrayList to a Method that returns an ArrayList
---------------------------------------------------------------------------------------------------------
On the Final Exam, it's fair game for you to be expected to write the FULL Java code for any and/or all of the:
-Bubble Sort, Selection Sort, Insertion Sort
-Binary Search
to solve a specific problem
Sorting - Simplified
Selection Sort - Pseudocode and Walkthrough
Bubble Sort - Pseudocode and Walkthrough
Insertion Sort - Pseudocode and Walkthrough
Sorting Algorithms
Video demonstration of Bubble Sort, Shell Sort and Quicksort
A Sorting Race!
Overview of the Quick Sort Algorithm
Sorting Summary Article with Animations
A Comparative Sorting Algorithm GIF
Searching Algorithms
Binary Search - Pseudocode and Walkthrough
Binary Searching for a Date - Flamenco Style!
Sorting and Searching Practice - do this...no..REALLY! DO THIS!!! TESTABLE MATERIAL
Passing An ArrayList to a Method that returns an ArrayList
Big 'O' Notation - Time Efficiency of Algorithms
Lecture - Big O and Comparable Interface concepts
Tutorial - The Comparable Interface
Article on Big 'O' Notation
A Gentle Explanation of Logarithmic TIme Complexity
What the current system clock time? (for analyzing execution time for an algorithm)
long startTime = System.currentTimeMillis();
.... your algorithm
long duration - System.currentTimeMillis - startTime;
System.out.println(duration);