Skip to content

Instantly share code, notes, and snippets.

@dhust
Last active December 20, 2015 14:09
Show Gist options
  • Select an option

  • Save dhust/6144568 to your computer and use it in GitHub Desktop.

Select an option

Save dhust/6144568 to your computer and use it in GitHub Desktop.
An example of associative arrays. That means there are two arrays where the elements are related (associated) to one another.
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.");
}
}
/* OUTPUT:
Snoop Dogg is 41 years old.
Justin Bieber is 18 years old.
Hoodie Allen is 23 years old.
Taylor Swift is 22 years old.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment