how to constrain a collection so it takes only strings
Constrain arrayList
Collapse
X
-
Yes that is correct. Without using 1.5 you'd have to write yuor own ArrayList class and put the restriction on the add method.Originally posted by Ganon11I think as of Java5 or Java6, you can declare an ArrayList with a class or data type inside <> brackets, like:
and this will restrict myStringList to holding Strings.Code:ArrayList<String> myStringList = new ArrayList<String>();
Comment
Comment