CodeGym-17~20
0.如果是基本数据类型的话,在数组中就存储特定的值;如果是对象的话,在数组中就是存储对象的引用。
1.数组本身就是对象
0.Arrays.sort(array); Arrays.toString(array);(重写了toString方法) Arrays.copyOf(array,length);(返回复制以后的数组,也可以复制二维数组) Arrays.copyOfRange(array, start_index,end_index);
1.数组类并没有重写equals方法,但是Arrays类重写了equals方法。Arrays.equals(array1,array2); Arrays.deepEquals(array1,array2); Arrays.deepToString(array1,array2);
0.
ArrayList的size不定的根据:
- When the internal array is filled, ArrayList creates a new array internally. The size of the new array is the size of the old array times 1.5 plus 1.
- All the data is copied from the old array into the new one。
- The old array is cleaned up by the garbage collector.
indexOf(); get(); add(); contain(); set();(与add有区别) clear(); asList();{ArrayList<Cat> catsList = new ArrayList<>(Arrays.asList(catsArray));(使用方法)} toArray();
size();
1.未解决问题:ArrayList<Cat> cats = new ArrayList<>(); ArrayList<Cat> cats = new ArrayList<Cat>();两者区别
0.You cannot simultaneously iterate over a collection and change its elements.(不能同时迭代集合并更改其中的元素,包括插入,删除等操作)
要实现迭代时还要更改其中的内容,就要用到Iterator类
hasNext()
- returns true or false, depending on whether there is a next item in the list, or we have already reached the last one.next()
- returns the next item in the listremove()
- removes an item from the list
Iterator<Cat> catIterator = cats.iterator();// Create an iterator
while(catIterator.hasNext()) {// As long as there are elements in the list Cat nextCat = catIterator.next();// Get the next element
System.out.println(nextCat);// Display it
}
关于remove()方法:remove()
removes the last element returned by the iterator.
remove()方法的使用:
Iterator<Cat> catIterator = cats.iterator();// Create an iterator
while(catIterator.hasNext()) {// As long as there are elements in the list Cat nextCat = catIterator.next();// Get the next element
if (nextCat.name.equals("Lionel Messi")) {
catIterator.remove();// Delete the cat with the specified name
}
} System.out.println(cats);
最新文章
- 性能测试工具 wrk 安装与使用
- Android Studio NDK编程-环境搭建及Hello!
- psp工具需求分析
- UvaOJ10369 - Arctic Network
- javascript对象初探(一)--- 构造器函数
- 东大OJ-1588: Routing Table
- August 7th 2016, Week 33rd Sunday
- 分布式PostGIS系列【2】——pgpool-II
- Android_2015-04-07 Android中Intent的使用
- [HDU1017]Exact cover[DLX][Dancing Links详解][注释例程学习法]
- STM32与LPC系列ARM资源之比较
- 在Linux中让文本显示带颜色的字。
- C#推送RTMP到SRS通过VLC进行取流播放!!
- crontabs linux定时任务功能安装
- python的partial()用法说明
- WinlogonHack获取系统密码
- Python开发【Django】:组合搜索、JSONP、XSS过滤
- Laravel 学习记录
- 【CQOI 2007】 余数求和
- PostgreSQL full_page_write记录