有意思的可变数组依据tomcat生命周期的lifeSupport

来源:互联网 发布:天龙八部淘宝抢号行吗 编辑:程序博客网 时间:2024/06/05 17:20
依据tomcat源码中的LifecycleSupport.addLifecycleListenerpackage com.array;public class ArrayTest {private static String str1[] = new String[0];public static void main(String[] args) {for (int i = 0; i < 10; i++)testArrayExtend(i + "");}private static void testArrayExtend(String args) {String str2[] = new String[str1.length + 1];for (int i = 0; i < str1.length; i++) {str2[i] = str1[i];}str2[str1.length] = args;str1 = str2;System.out.println(str1.length);}}