转:Java中字符串split() 的使用方法.

原文:https://blog.csdn.net/qq_27093465/article/details/54910323

挺有意思的一个问题

先看下面的方法,事先预测一下,经过split方法,按逗号进行分割为数组之后,生成的数组的长度是多少,目测很多人都觉得是8,但是结果却出乎意料。是5而不是8.

private static void testSplit() {        String ss = ",aa,bb,cc,dd,,,";        String[] array = ss.split(",");         System.out.println(array.length);//结果是5,而不是预想中的8        for (int i = 0; i < array.length; i++) {            System.out.println(array[i]);        }    }

---------------------

本文来自 李学凯 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/qq_27093465/article/details/54910323?utm_source=copy 

学习了~

详细内容见 原文博客~

猜你喜欢

转载自www.cnblogs.com/mumu122GIS/p/9709832.html