資源描述:
《Java分割數(shù)組成子數(shù)組.docx》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、Java分割數(shù)組成子數(shù)組分類:?Java2011-10-2012:51?5448人閱讀?評論(0)?收藏?舉報(bào)javaobjectlistimportstringclass?我有一個(gè)2000多長度的數(shù)組,我要分割成40個(gè)50長度的子數(shù)組,怎么實(shí)現(xiàn)?問題補(bǔ)充:我需要的結(jié)果是這樣的:把這個(gè)數(shù)組int[]sum={0,1,2,3,4,5,……,18};分成int[]a={0,1,2,3,4};//長度5int[]b={5,6,7,8,9};//長度5int[]c={10,11,12,13,14};//長度5int[]d={15,16,17,18};//長度4[javascript]?view
2、plaincopy1.import?java.util.ArrayList;??2.import?java.util.List;??3.??4.public?class?ABC?{??5.??6.?public?static?void?main(String[]?args)?{??7.??8.??int[]?ary?=?{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};//要分割的數(shù)組??9.??int?splitSize?=?5;//分割的塊大小??10.??????11.???Object[]?subAry?=?splitAry(ar
3、y,?splitSize);//分割后的子塊數(shù)組??12.?????13.??for(Object?obj:?subAry){//打印輸出結(jié)果??14.?????15.???int[]?aryItem?=?(int[])?obj;??16.?????17.???for(int?i?=?0;?i?
4、tatic?Object[]?splitAry(int[]?ary,?int?subSize)?{??4.??int?count?=?ary.length?%?subSize?==?0???ary.length?/?subSize:?ary.length?/?subSize?+?1;??5.??6.??List>?subAryList?=?new?ArrayList>();??7.??8.??for?(int?i?=?0;?i?5、????11.???List?list?=?new?ArrayList();??12.???int?j?=?0;??13.???while?(j?6、?for(int?i?=?0;?i??subList?=?subAryList.get(i);??25.?????26.???int[]?subAryItem?=?new?int[subList.size()];??27.???for(int?j?=?0;?j?
7、tem;??32.??}??33.????34.??return?subAry;??35.?}??36.}??------------------0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,