2013年9月17日星期二

list.get (0) and list.get (i)

list.get (0) and list.get (i)
seeking to explain the next list.get (0) and list.get (i)
difference between the two ?
------ Solution ---------------------------------------- ----
list.get (0) to get the first element
list.get (i) (i +1) -th element obtained

landlord to take a look at the basis of it
------ Solution ------------------------------ --------------
List list = new ArrayList ();
for (int i = 0; i People people = list.get (i);
}
/ / When i = 0 , the acquire is the list the first element in the collection ,
/ / when i = 1 , the list is made ​​the second element in the collection ,
......
/ / when i = i when the list is made ​​in the collection (i +1) -th element .
------ Solution ---------------------------------------- ----
an access list is the first element in the collection , and the second element is to obtain the specified index .
------ Solution ---------------------------------------- ----
somewhat similar and arrays : a [0] and a [i] difference
------ Solution ----------------- ---------------------------
List list = new ArrayList ();
list.add (xxx);
list.add (yyy);
...


list.get (0); is to obtain list inside index 0 ( which is the first one ) element
list.get (i); the index i for which the list ( that is, (i +1) a ) Elements
i is an integer variable , such as int i = 5; then the index is out of 5 ( Section 6 ) Elements
list.get (i) is more common in the traversal time , such as
for (int i = 0; i System.out.println (list.get (i));
}


------ Solution ------------------------------------ --------

List ArrayList example in order to achieve the underlying is an array
get (index) is actually accessed through the array subscript , so
lacks distinction
------ For reference only ------------------------------- --------
learn

没有评论:

发表评论