怎样取一个List当中的前N个数据

a470 2013-11-09 11:04:58
我觉得循环感觉不是很好,会不会效率很低呢?
for(){

}
有没有其他方法?
...全文
1646 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
a470 2013-11-09
  • 打赏
  • 举报
回复
引用 1 楼 huxiweng 的回复:
去看下Arrays.copyOf
public static <T> T[] copyOf(T[] original, int newLength) Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain null. Such indices will exist if and only if the specified length is greater than that of the original array. The resulting array is of exactly the same class as the original array. Parameters: original - the array to be copied newLength - the length of the copy to be returned Returns: a copy of the original array, truncated or padded with nulls to obtain the specified length Throws: NegativeArraySizeException - if newLength is negative NullPointerException - if original is null Since: 1.6 这个里面方法挺多的,要好好研究下。谢谢
teemai 2013-11-09
  • 打赏
  • 举报
回复
去看下Arrays.copyOf

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧