常用类demo--【J2SE】

StringBuffer类

		public class TestStringBuffer{
			public static void main(String[] args){
				String s="Mircosoft";
				char[] a={'a' ,'b' ,'c'};
				StringBuffer sb1=new StringBuffer(s);
				sb1.append('/').append("IBM").append('/').append("Sun");
				System.out.println(sb1);
				StringBuffer sb2=new StringBuffer("数字");
				for (int i=0;i<=9;i++){
					sb2.append(i);
				}
				System.out.println(sb2);
				sb2.delete(8,sb2.length());
				System.out.println(sb2);
				System.out.println(sb2.reverse());
			}
		

}

 

Stringbuffer是可变的,String是不可变的。

File类

		import java.io.*;
		//把所有的孩子的递归都列出来
		public class FileList{
			public static void main(String[] args){
				File f=new File("d:/A");
				tree(f);
			}
			private static void tree(File f){
				File[] childs=f.listFiles();
				for(int i =0;i<childs.length;i++){
					System.out.println(childs[i].getName());
					if(childs[i].isDirectory()){
						tree(childs[i]);
					}
				}
			}
		}

枚举类型:

		public class TestEnum{
			
			public enum MyColor{red,green,blue};
		
			
			public static void main(String[] args){
				MyColor m=MyColor.red;
				switch(m){
						case red:
						System.out.println("red");
						break;
						case green:
							System.out.println("green");
							break;
						default:
							System.out.println("default");			
				}
				
				System.out.println(m);
			}
		}

原文地址:https://www.cnblogs.com/wangmei/p/4822327.html