摘要: import java.util.ArrayList; import java.util.Collection; public class Test { public static void main(String[] args) { Collection<Object> c = new ArrayList<Object>(); c.add("hello"); c.add(new Name("f1", "l1")); c.add(new Integer(100)); System.out.println(c.s 阅读全文
posted @ 2012-04-30 20:29 spring3 阅读(273) 评论(0) 推荐(0) 编辑
摘要: public class Test { 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; case blue: System.out.println("blue")... 阅读全文
posted @ 2012-04-30 20:02 spring3 阅读(157) 评论(0) 推荐(0) 编辑
摘要: import java.io.File; public class Test { public static void main(String[] args) { File f = new File("C:/java"); listFileTree(f,0); } private static void listFileTree(File f,int level) { String preStr = ""; for(int i = 0; i < level; i++) { preStr += " "; } File[] ... 阅读全文
posted @ 2012-04-30 19:53 spring3 阅读(168) 评论(0) 推荐(0) 编辑
摘要: import java.io.File; import java.io.IOException; public class TestFile { public static void main(String[] args) { String separator = File.separator; String fileName = "myfile.txt"; String directory = "mydir1" + separator + "mydir2"; File f = new File(directory, fileName 阅读全文
posted @ 2012-04-30 19:35 spring3 阅读(233) 评论(0) 推荐(0) 编辑
摘要: public class Test { public static void main(String[] args) { double a = Math.random(); double b = Math.random(); System.out.println(Math.sqrt(a*a+b*b)); System.out.println(Math.pow(a, 8)); System.out.println(Math.round(b)); System.out.println(Math.log(Math.pow(Math.E, 15))); double d ... 阅读全文
posted @ 2012-04-30 19:08 spring3 阅读(248) 评论(0) 推荐(0) 编辑
摘要: public class Test { public static void main(String[] args) { String s = "1,2;3,4,5;6,7,8"; double [][] d; String [] sFirst = s.split(";"); d = new double[sFirst.length][]; for(int i = 0; i < sFirst.length; i++) { String [] sSecond = sFirst[i].split(","); d[i] = new d 阅读全文
posted @ 2012-04-30 16:26 spring3 阅读(2248) 评论(0) 推荐(0) 编辑
摘要: public class Test { public static void main(String[] args) { Integer i = new Integer(100); Double d = new Double("123.456"); int j = i.intValue() + d.intValue(); float f = i.floatValue() + d.floatValue(); System.out.println(j); System.out.println(f); double pi = Double.parseDoub... 阅读全文
posted @ 2012-04-30 16:00 spring3 阅读(213) 评论(0) 推荐(0) 编辑
摘要: public class TestBuffer {//StringBuffer存储变长的字符序列 ,String类是不可变长的字符序列 public static void main(String[] args) { String s = "Mircosoft"; char [] c = {'a', 'b', 'c'}; StringBuffer sb1 = new StringBuffer(s); sb1.append('/').append("IBM").append('/ 阅读全文
posted @ 2012-04-30 15:40 spring3 阅读(197) 评论(0) 推荐(0) 编辑
摘要: public class Test { public static void main(String[] args) { String s = "sunjavahahajavaokjavamyjavagoodjava"; String sToFind = "java"; int count = 0; int index = s.indexOf(sToFind); if(index != -1) { count ++; } s = s.substring(index + sToFind.length()); while(s.indexOf... 阅读全文
posted @ 2012-04-30 14:55 spring3 阅读(255) 评论(0) 推荐(0) 编辑
摘要: public class Test { public static void main(String[] args) { //String s = "48WERSFas!@#"; String s = "23479odurqjPOWUER00*)*&)(#084234-9LRWEJRLJ5R2)*q#)*puFOURoupPU_(*"; int countNum = 0; int countUpperCase = 0; int countLowerCase = 0; int countOther = 0; char[] sc = new char 阅读全文
posted @ 2012-04-30 14:17 spring3 阅读(545) 评论(0) 推荐(0) 编辑
摘要: //String类常用方法集锦public class TestString { public static void main(String[] args) { String s1 = "sun java"; String s2 = "Sun Java"; //取字符 System.out.println(s1.charAt(1));//u //长度 System.out.println(s2.length());//8 //子串位置 System.out.println(s1.indexOf("java"));//4 System 阅读全文
posted @ 2012-04-30 13:21 spring3 阅读(1563) 评论(0) 推荐(0) 编辑
摘要: public class Test { public static void main(String[] args) { String s1 = "hello"; String s2 = "world"; String s3 = "hello"; System.out.println(s1 == s3); //true System.out.println(s1.equals(s3));//true s1 = new String("hello"); s2 = new String("hello" 阅读全文
posted @ 2012-04-30 11:13 spring3 阅读(165) 评论(0) 推荐(0) 编辑
摘要: public class TestSort { public static void main(String[] args) { Date[] days = new Date[5]; //定义5个Date days[0] = new Date(2006, 8, 6); days[1] = new Date(2007, 4, 6); days[2] = new Date(2008, 4, 9); days[3] = new Date(2004, 4, 6); days[4] = new Date(2009, 4, 5); //要找的Date Date... 阅读全文
posted @ 2012-04-30 10:39 spring3 阅读(208) 评论(0) 推荐(0) 编辑