Java笔记 split/不定长度参数/泛型类型通配符
今天看了一下午《Java学习笔记》,作者林信良,花名良葛格。从书中所获颇 多,正所谓温故而知新,我就把今天的"新"总结一下,加深记忆。良葛格也提倡"在网上写文章是我记录所学的一种方式"。 split的正则式和其中的正则式 C语言其中有函数strtok,就是按某些char对字符串进行切割。下面给出一个C下面的范例 char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is "%s"n", result ); result = strtok( NULL, delims ); } 在Java中也有类似的StringTokenizer,但是在JDK5中,已经被标记为Legacy Class(遗产类),推荐使用String.split(String regex),可以接受正则表达式。范例如下。 ...