Unit 4: Data Collections Introduction to Arrays - Long Nguyen
array: object that stores many values of the same type. – value: One value in an array. – index: A 0-based integer to access an element from an array ...
array: object that stores many values of the same type. – value: One value in an array. – index: A 0-based integer to access an element from an array ...
The Enhanced For Loop If you are working with arrays(or other collections data structures), you can use an alternative syntax for a for loop (enhanced form of for loop) to iterate through items of arrays/collections.
Comparing strings With String objects, you must use the equals method to test if two strings have the same characters in the same order instead of == which is used for primitive types.
But you'll likely need to use the method in your code at least once. AVOID using arrays/arraylists for this problem. 2019 #1 is a good example of this problem.
Type casting • type cast: A conversion from one type to another. – To promote an int into a double to get exact division from / – To truncate a double from a real number to an integer • Syntax:
MUST USE a for each loop. Write the method longest which accepts an arraylist of strings and return the longest string. Return the first one if there are multiple longest strings. MUST USE a regular for loop. Write the method remove which accepts an arraylist of Integers list and an integer variable x. Remove all occurrences of x in list.
The convention in Java and many programming languages is to always start a variable name with a lower case letter and then uppercase the first letter of each additional word.