arrays - How to add item to a list of arraylist that filled before in java -
i have booklist below
public static arraylist<list<string>> bookslist = new arraylist<list<string>>(); and filled shown below,
bookslist.add(arrays.aslist("coders @ work", null)); bookslist.add(arrays.aslist("code complete",null)); bookslist.add(arrays.aslist("the mythical man month",null)); bookslist.add(arrays.aslist("don't make me think",null)); bookslist.add(arrays.aslist("the pragmatic programmer",null)); i want add item list of specific row of arraylist
bookslist.get(0).add("buyed"); bookslist.get(0).add(0,"buyed"); but doesn't work. how add more items? or there better way handle situation?
you cannot add or remove elements of list created arrays.aslist().
its javadoc states indeed :
returns fixed-size list backed specified array.
to able add new elements after list created, wrap fixed size list in new arraylist.
for example :
bookslist.add(arrays.aslist("coders @ work", null)); could written :
bookslist.add(new arraylist<>(arrays.aslist("coders @ work", null)));
Comments
Post a Comment