This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
// Three "calls" to the method 'printStuff' | |
printStuff(); | |
printStuff(); | |
printStuff(); | |
} | |
// This code only runs if it's "called" | |
public static void printStuff () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
ArrayList <String> people = new ArrayList < String> (); | |
people.add("Dave"); | |
people.add("Andrew"); | |
people.add("John"); | |
for (int i=0; i<people.size(); i++) { | |
System.out.println(people.get(i)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
String[] artist = {"Snoop Dogg", "Justin Bieber", "Hoodie Allen", "Taylor Swift" }; | |
int[] ages = { 41, 18, 23, 22 }; | |
for (int i=0; i<artist.length; i++) { | |
System.out.println(artist[i] + " is " + ages[i] + " years old."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***** Declaring an array of 10 Strings *****/ | |
String[] myList = new String[10]; | |
// prints the second element of the array, since it's [1] | |
System.out.println( myList[1] ); | |
/***** Declaring and initializing an array of 10 Strings *****/ | |
String[] myList = { null, null, null, null, null, null, null, null, null, null }; | |
// prints the second element of the array | |
System.out.println(myList[1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***** Declaring an array of 10 Strings *****/ | |
String[] myList = new String[10]; | |
// prints the second element of the array, since it's [1] | |
System.out.println( myList[1] ); | |
/***** Declaring and initializing an array of 10 Strings *****/ | |
String[] myList = { null, null, null, null, null, null, null, null, null, null }; | |
// prints the second element of the array | |
System.out.println(myList[1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***** Declaring an array with a set size. The array is automatically filled with zeros. *****/ | |
int[] myList = new int[10]; | |
// prints the first element of the array, since it's [0] | |
System.out.println( myList[0] ); | |
/***** Declaring & initializing the array with zeros *****/ | |
int[] myList = { 0,0,0,0,0,0,0,0,0,0 }; | |
// prints the first element of the array | |
System.out.println(myList[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
// Make an array to hold people's names | |
ArrayList <String> people = new ArrayList < String> (); | |
// Add people's names to the array | |
people.add("Dave"); | |
people.add("Andrew"); | |
people.add("John"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
for (declare a variable : array to iterate through) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
// Make an array | |
ArrayList <String> people = new ArrayList <String> (); | |
// Add some people to it | |
people.add("Dave"); | |
people.add("Andrew"); | |
people.add("John"); |