From ggc
|
01 packagepackage is used to name the directory or folder a class is in intro;
02 //start auto-imports
03 importimport means to make the classes and/or packages available in this program java.util.*;
04 //end auto-imports
05
06 importimport means to make the classes and/or packages available in this program wiki.Wiki;
07
08 /**
09 * All about my application.
10 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
11 */
12 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects ArrayListReview
13 {open braces start code blocks and must be matched with a close brace
14
15 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args)
16 {open braces start code blocks and must be matched with a close brace
17 //declaring an ArrayList of integers called numbers
18 ArrayList<Integer> numbers;
19 //intialize the ArrayList
20 numbers=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Integer>();
21 //put the number 5 in the first position of the ArrayList
22 numbers.add(5);//don't do numbers[0] because it's an ArrayList
23 numbers.add(15);
24 Wiki.out.println("The ArrayList has a capacity of "+adds two numbers together or concatenates Strings together numbers.size());
25 Wiki.out.println("Printing using standard for loop.");
26 //standard for loop
27 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<numbers.size(); i++this is the increment operator, which increases the variable by 1)
28 {open braces start code blocks and must be matched with a close brace
29 Wiki.out.println("number["+adds two numbers together or concatenates Strings togetheri+adds two numbers together or concatenates Strings together"] is "+adds two numbers together or concatenates Strings togethernumbers.get(i));//don't do number[i] since it's and ArrayList
30 }close braces end code blocks and must match an earlier open brace
31 Wiki.out.println("Printing using enhanced for loop.");
32 //enhanced for loop
33 intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0;
34 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer single: numbers)
35 {open braces start code blocks and must be matched with a close brace
36 Wiki.out.println("number["+adds two numbers together or concatenates Strings togetheri+adds two numbers together or concatenates Strings together"] is "+adds two numbers together or concatenates Strings togethersingle);
37 i++this is the increment operator, which increases the variable by 1;
38 }close braces end code blocks and must match an earlier open brace
39 }close braces end code blocks and must match an earlier open brace
40 }close braces end code blocks and must match an earlier open brace
|
Download/View intro/ArrayListReview.java