toString,Array.toList(Object[])
package c11;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author admin
*
*/
public class InfiniteRecursion {
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
/**
*TODO Auto-generated method stub
*return super.toString();
*/
// return "InfiniteRecursion address :"+this+"\n"; //这个会产生递归电泳
return super.toString();
}
public static void main(String[] args) {
InfiniteRecursion ir=new InfiniteRecursion();
System.out.println("--"+ir);
List<String> list=new ArrayList<String>();
list.add("haha");
list.add("hello world!");
Object[] os=list.toArray();
String[] arr=new String[4];
arr[0]="test0";
arr[1]="test1";
arr[2]="test2";
arr[3]="test3";
/*
将list的数据保存到arr数组中,如果arr的长度不够,将不能存入,如果过长,则以null填补;
如果arr的长度大于list,且本身包含数据时,则其arr[size]将被重新赋值为null,这是由于ArrayList中的toArray
public <T> T[] toArray(T[] a) {
if (a.length < size)
// Make a new array of a's runtime type, but my contents:
return (T[]) Arrays.copyOf(elementData, size, a.getClass());
System.arraycopy(elementData, 0, a, 0, size);
if (a.length > size)
a[size] = null;
return a;
}
*/
list.toArray(arr);
String tostr=Arrays.asList(arr).toString();
System.out.println(tostr);
list.contains(new Object());
}