To better understand, let’s look at the following example:
package com.yonyou.test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * Test class* @author Wulin.com* @Creation date 2016-5-31 */ public class Test{ public static void main(String[] args) { List<String> list=new ArrayList<String>(); list.add("Hello"); list.add("World"); list.add("HAHAHAHA"); String[] strArray2=new String[list.size()]; list.toArray(strArray2); for(int i=0;i<strArray2.length;i++) { System.out.println(strArray2[i]); } //The following content will have a cast error String[] strArray=(String[]) list.toArray(); //list.toArray() will return an array of Object[] type and want to cast to String[] for(int i=0;i<strArray.length;i++) { System.out.println(strArray[i]); } } }The above article briefly discusses the issue of coercive type conversion in Java is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.