java - Collapse 2D ArrayList -



java - Collapse 2D ArrayList -

i have object contains dynamically allocated 2d arraylist.

it has getter: arraylist<integer> getlist()

i'd function collapse 2d arraylist 1d arraylist. java have such thing or stuck doing this:

public arraylist<integer> getlist(){ arraylist<integer> result = new arraylist<integer>(); for(int = 0; < list_.size(); i++){ for(int j = 0; j < list_.get(i).size(); j++){ result.add(list_.get(i).get(j)); } } homecoming result; }

without java 8, have utilize loops. using addall(..) rid of 1 of them though.

public arraylist<integer> getlist(){ arraylist<integer> result = new arraylist<integer>(); for(arraylist<integer> : list_){ result.addall(i); } homecoming result; }

also, generic types such arraylist must object types, hence integer, not int.

java arraylist multidimensional-array dynamic-arrays

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -