java - Order of list's elements -
consider following enum:
public enum type{      integer,      double,      boolean } now, have following line:
list<type> types = arrays.aslist(type.values()); do list contains elements in same order put enum? order reliable?
yes. java language specification enums states:
/** * returns array containing constants of enum  * type, in order they're declared.  method may * used iterate on constants follows: * *    for(e c : e.values()) *        system.out.println(c); * * @return array containing constants of enum  * type, in order they're declared */ public static e[] values(); it returned array constants declared.
regarding arrays.aslist() method, can rely on order well:
returns fixed-size list backed specified array. (changes returned list "write through" array.)
consider below example, common way initialize list:
list<string> stooges = arrays.aslist("larry", "moe", "curly"); the order of list same in array.
Comments
Post a Comment