上一页 1 ··· 3 4 5 6 7 8 下一页
摘要: 1.自然排序2.存储对象对象实现Comparable接口 1 import java.util.Iterator; 2 import java.util.TreeSet; 3 4 public class TreeSetDemo { 5 public static void main(String[] args){ 6 TreeSet<Student> ts =new TreeSet<Student>(); 7 ts.add(new Student(21,"zhangsan")); 8 ts.add(new Student(29,"li.. 阅读全文
posted @ 2012-07-07 01:31 Carve_Time 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 1.创建对象 对于java程序中的字符串直接常量,JVM会使用一个字符串池来保存它们。当第一次使用某个字符串直接常量时,JVM会将它放入字符串池中进行缓存。在一般情况下,字符串池中的字符串对象不会被垃圾回收。当程序再次需要使用该字符串时,无需重新创建一个新的字符串就可以直接让引用变量直接指向字符串中已有的字符串。而使用new操作创建的字符串对象不指向字符串池中的对象,但是可以使用intern()方法使其指向字符串池中的对象。1 public class StringDemo1 {2 public static void main(String[] args){3 Str... 阅读全文
posted @ 2012-06-30 19:30 Carve_Time 阅读(226) 评论(0) 推荐(0) 编辑
摘要: final变量final变量的初始化方式:1.在定义的时间初始化2.final变量可以在初始化块中初始化,但不可以在静态初始化块中初始化3.静态final变量可以在静态初始化块中初始化,但不可以在初始化块中初始化。4.final变量可以在构造函数中初始化,静态final变量不可以。class FinalDemo { public static void main(String[] args) { Person p =new Person("张三"); System.out.println(p.name); } } class Pers... 阅读全文
posted @ 2012-06-30 18:52 Carve_Time 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 常见面试题:Collection 和 Collections的区别。Collections是个java.util下的类,它包含有各种有关集合操作的静态方法。Collection是个java.util下的接口,它是各种集合结构的父接口。Colletions常用方法: 阅读全文
posted @ 2012-06-30 16:53 Carve_Time 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 缓冲区优点:1.更加高效BufferedWriter特有方法:newLine()方法。BufferedReader特有方法readLine()方法自定义输出:每行加行号:public class MyFileReader { private FileReader fr; private int lineNumber=1; MyFileReader(FileReader fr){ this.fr =fr; } public String myReadLine() throws IOException{ StringBuilder sb =... 阅读全文
posted @ 2012-06-30 15:14 Carve_Time 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 枚举特点1.用enum定义枚举类默认继承了java.lang.Enum类而不是继承了Object类。其中java.lang.Enum类实现了java.lang.Serializable和java.lang.Comparable两个接口2.枚举类的构造函数只能使用private访问修饰符,如果省略了其构造器的访问控制符,则默认使用private修饰;3.枚举类的所有实例必须在枚举类中显式列出,否则这个枚举类将永远都不能产生实例。列出这些实例时,系统会自动添加public static final修饰,无需程序员显式添加。public enum Week { MON{ publ... 阅读全文
posted @ 2012-06-30 00:03 Carve_Time 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 1、取出一个字符串中字母出现的次数。如:字符串:"abcdekka27qoq",输出格式为:a(2)b(1)k(2)... 1 import java.util.Iterator; 2 import java.util.Map; 3 import java.util.Map.Entry; 4 import java.util.Set; 5 import java.util.TreeMap; 6 7 public class Test1 { 8 public static void main(String[] args){ 9 String str ="abcdek 阅读全文
posted @ 2012-06-28 18:31 Carve_Time 阅读(320) 评论(0) 推荐(0) 编辑
摘要: 构造函数 1 public class FileDemo { 2 public static void main(String[] args){ 3 //构造函数File(String pathname) 4 File f1 =new File("c:\\abc\\1.txt"); 5 //File(String parent,String child) 6 File f2 =new File("c:\\abc","2.txt"); 7 //File(File parent,String child) 8 ... 阅读全文
posted @ 2012-06-28 15:41 Carve_Time 阅读(241) 评论(0) 推荐(0) 编辑
摘要: 内部类访问规则内部类可以直接访问外部类中的成员,包括私有。访问格式:外部类名.this外部类要访问内部类必须创建内部类对象。内部类在成员位置上,可以被成员修饰符修饰。 1 public class InnerClassDemo1 { 2 public static void main(String[] args){ 3 Outer ou =new Outer(); 4 ou.method();// 4 3 5 Outer.Inner oi =new Outer().new Inner(); 6 oi.function2(... 阅读全文
posted @ 2012-06-26 23:32 Carve_Time 阅读(290) 评论(0) 推荐(1) 编辑
摘要: ★打印九九乘法表 1 public class TestDemo { 2 public static void main(String[] args){ 3 for(int b=1;b<10;b++){ 4 for(int a=1;a<=b;a++) 5 System.out.print(a+"*"+b+"="+a*b+"\t"); 6 System.out.println(); 7 } 8 } 9 10 }11 /*12 1*1=1 13 1*2=2 2... 阅读全文
posted @ 2012-06-26 23:24 Carve_Time 阅读(216) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 下一页