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")); } }
输出
1
2
3
|
size
:
3
contain:a?:true
contain: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()); } }
结果
1
2
|
This!! :
9
This!!:
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)); } }
结果
1
2
3
|
This!! umusual use!!of exclamation!!points
[This, umusual use, of exclamation, points]
[This, umusual use, of exclamation!!points]
|
说明
split()第二个参数表示分割的字符串个数不超过该参数
本文转自jihite博客园博客,原文链接:http://www.cnblogs.com/kaituorensheng/p/3923885.html,如需转载请自行联系原作者