I just started learning about the ArrayList class in Java. I have the following code below testing out the ArrayList class and it's methods:
import java.util.ArrayList;
public class NewArrayList {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<String> myList = new ArrayList<String>();
String s = new String();
myList.add(s);
String b = new String();
myList.add(b);
int theSize = myList.size();
System.out.println("ArrayList size: " + theSize);
boolean isTrue = myList.contains(s);
System.out.println(isTrue);
int whereIsIt = myList.indexOf(s);
System.out.println(whereIsIt);
int whereIsIt2 = myList.indexOf(b);
System.out.println(whereIsIt2);
}
}
The indexOf method shows whats the index of an object. So since I added two objects, s and b to the myList ArrayList object reference, it should have 2 objects inside the index. The output of whereIsit and whereIsit2 is both 0. Shouldn't it be 0 1??