...
| Code Block | ||
|---|---|---|
| ||
public class Wrapper {
public static void main(String[] args) {
// Create an array list of integers, where each element
// is greater than 127
ArrayList<Integer> list1 = new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
list1.add(i + 1000);
}
// Create another array list of integers, where each element
// has the same value as the first one
ArrayList<Integer> list2 = new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
list2.add(i + 1000);
}
// Count matching values
int counter = 0;
for (int i = 0; i < 10; i++) {
if (list1.get(i).equals(list2.get(i))) { // uses 'equals()'
counter++;
}
}
// Print the counter: 10 in this example
System.out.println(counter);
}
}
|
...
| Code Block | ||
|---|---|---|
| ||
public void exampleEqualOperator(){
Boolean b1 = true; // Or Boolean.True
Boolean b2 = true; // Or Boolean.True
if (b1 == b2) { // always equal
System.out.println("Will always be printedAlways print");
}
}
|
Exceptions
EXP03-EX0 In the unusual case where a program is guaranteed to execute only on a single implementation, it is permissible to depend on implementation-specific ranges of memoized values.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="feeef696d6af6fd4-0ebfbd10-4334472c-a3648bd9-7e0fa76f82495f9f9f3d268e"><ac:plain-text-body><![CDATA[ | [[Bloch 2009 | AA. Bibliography#Bloch 09]] | 4, Searching for the One | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="4f3edc13b6a3de0d-04810ff8-4dcf4c76-88fe808d-cb49e2a281a66def952e25bb"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [§5.1.7, Boxing Conversion | http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.7] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="388d9fb18986a24c-fd139afa-4a2544d2-8d14a23d-ae8c5091d6e5e7d4d8395f9a"><ac:plain-text-body><![CDATA[ | [[Pugh 2009 | AA. Bibliography#Pugh 09]] | Using == to compare objects rather than .equals | ]]></ac:plain-text-body></ac:structured-macro> |
...