对集合类AbstractCollection借口toString方法的this关键字理解
来源:互联网 发布:com域名不备案能解析吗 编辑:程序博客网 时间:2024/04/20 09:10
/**
* Returns a string representation of this collection. The string
* representation consists of a list of the collection's elements in the
* order they are returned by its iterator, enclosed in square brackets
* (<tt>"[]"</tt>). Adjacent elements are separated by the characters
* <tt>", "</tt> (comma and space). Elements are converted to strings as
* by {@link String#valueOf(Object)}.
*
* @return a string representation of this collection
*/
public String toString() {
Iterator<E> i = iterator();
if (! i.hasNext())
return "[]";
StringBuilder sb = new StringBuilder();
sb.append('[');
for (;;) {
E e = i.next();
sb.append(e == this ? "(this Collection)" : e);
if (! i.hasNext())
return sb.append(']').toString();
sb.append(", ");
}
}
当
ArrayList<ArrayList> a=new ArrayList<ArrayList>();
a.add(a);
System.out.println(a);
a.add(a);
System.out.println(a);
时会输出
[(this Collection)]
可见当一个集合类的泛型是其自身
并且把自己假如到自己的集合中去
就会打印 “this Collection”
1 0
- 对集合类AbstractCollection借口toString方法的this关键字理解
- 对this关键字的理解
- 第三课 return关键字的用法、toString()方法、this关键字
- 对javascript中this关键字的理解
- js中对this关键字的理解
- 对Java中this关键字的理解
- 个人对this关键字理解
- this关键字的理解。
- this关键字的理解
- 对ToString("X2 ")的理解
- 对ToString("X2 ")的理解
- 对ToString("X2 ")的理解
- 对ToString("X2")的理解
- 对ToString("X2 ")的理解
- Java 集合深入理解(5):AbstractCollection
- Java 集合深入理解(5):AbstractCollection
- Java 集合深入理解(5):AbstractCollection
- 本人对this super static 关键字的理解
- 任务管理器无法中止进程怎么办
- ios 性能优化之ImageView的那些事
- android studio强制关闭运行报错
- [从头学数学] 第198节 数学史选讲
- oracle表的备份
- 对集合类AbstractCollection借口toString方法的this关键字理解
- 3Sum Closest(离目标值最近的三数之和)
- 互联网服务端技术——如何学(上)
- 匿名函数
- ActiveMQ将消息持久化到数据库
- Java设计模式--策略模式
- PE 290【数位DP】
- DWR入门教程
- OSv—Optimizing the Operating System for Virtual Machines 5