1. ArrayList()
import java.util.*; public class Test{ public static void main(String [] args){ ArrayList list = new ArrayList(); list.add("a"); list.add("b"); list.add("c"); System.out.println("size:" + list.size()); System.out.println("contain:a?:" + list.contains("a")); System.out.println("contain:d?:" + list.contains("d")); }}
输出
size:3contain:a?:truecontain:d?:false
2. 数组
public class TestNew { public static void main(String args[]) { int[] s ; int i ; s = new int[5] ; for(i = 0 ; i < 5 ; i++) { s[i] = i ; } for(i = 4 ; i >= 0 ; i--) { System.out.println("" + s[i]) ; } } }
3. 字符串类型
trim(): 将String两端的空白字符删除
案例
import java.util.*;public class SplitDemo{ public static void main(String[] args) { String input = "\t This!!\t"; String input2 = input.trim(); System.out.println(input + ":" + input.length()); System.out.println(input2 + ":" + input2.length()); } }
结果
This!! :9This!!:6
split(): 以某个字符串切割
例子
import java.util.*;public class SplitDemo{ public static void main(String[] args) { String input = "This!! umusual use!!of exclamation!!points"; System.out.println(input); String arrayS1[] = input.split("!!"); System.out.println(Arrays.toString(arrayS1)); String arrayS2[] = input.split("!!", 3); System.out.println(Arrays.toString(arrayS2)); } }
结果
This!! umusual use!!of exclamation!!points[This, umusual use, of exclamation, points][This, umusual use, of exclamation!!points]
说明
split()第二个参数表示分割的字符串个数不超过该参数