看视频
文章平均质量分 72
我叫阿狸猫
这个作者很懒,什么都没留下…
展开
-
用迭代器取出ArrayList集合集合中的元素。(用for和while正反向遍历)
import java.util.*;class ListDemo1 { public static void main(String[] args) { ArrayList a=new ArrayList(); a.add("java01"); a.add("java02"); a.add("java03"); ListIterator t=a.listIterat原创 2012-04-28 13:28:41 · 3771 阅读 · 0 评论 -
匿名内部类
abstract class AbsDemo { abstract void show(); } class Demo { int x=3; public void method() { final int x=9; new AbsDemo() {原创 2012-04-21 17:20:43 · 411 阅读 · 0 评论 -
易错点!!!
interface A{}class B implements A{ public String func() { return "func"; }}class Demo{ public static void main(String[] args) { A a=new B(); System.out.println(a.func()); }}//此程序编译失原创 2012-04-22 17:48:21 · 477 阅读 · 0 评论 -
手动抛出自定义异常!
class FuShuException extends Exception{ FuShuException(String m) { super(m); }}class Demo{ int div(int a,int b)throws FuShuException { if(b<0) throw new FuShuException("大爷的,你会不会啊!!!");原创 2012-04-21 22:36:14 · 930 阅读 · 0 评论 -
补足代码
interface Inter { void method(); } class Test { static class Demo implements Inter { public void method() { System.out.println("哈哈哈哈");原创 2012-04-21 18:44:05 · 632 阅读 · 0 评论 -
当内部类定义在局部时
class Demo{int x=3;void method(final int a){class DemoLi{void method1(){System.out.println(a);}}new DemoLi().method1();}}class Demodemo5{public static void main(S原创 2012-04-21 16:38:29 · 417 阅读 · 0 评论 -
多态的应用
class Demo{private int num;Demo(int num){this.num=num;}public boolean equals(Object obj)//这里使用到了多态,这句话是覆写了Object中的方法{ //(覆写需要函数一摸一样,但是功能内容不一样) if (obj instanceof Demo)//public b原创 2012-04-21 15:01:52 · 401 阅读 · 0 评论 -
增强For遍历Map集合的要点!
import java.util.*;class ForTest{ public static void main(String[] args){ HashMaphm=new HashMap(); hm.put(1,"xxc1"); hm.put(2,"xxc2"); hm.put(3,"xxc3"); /*Sets=hm.keySet(); for(Integer i原创 2012-05-02 21:00:08 · 1099 阅读 · 0 评论 -
多态
abstract class Student{public abstract void study();public void sleep(){System.out.println("躺着睡");}}class BaseStudent extends Student{public void study(){System.out.println("Ba原创 2012-04-20 21:54:19 · 384 阅读 · 0 评论 -
多态,接口
interface PCI{ public abstract void open();public abstract void close();}class MainBoard{public void run(){System.out.println("MainBoard run");}public void usePCI(PCI p)原创 2012-04-20 23:00:13 · 407 阅读 · 0 评论 -
异常不可能全部同时发生
class Demo{ int div(int a,int b)throws ArithmeticException,ArrayIndexOutOfBoundsException { int arr[]=new int[a]; System.out.println(arr[4]); return a/b; }}class Demodemo8{ public sta原创 2012-04-21 21:19:04 · 488 阅读 · 0 评论 -
Struts1和Spring整合的步骤
* 搭建struts和spring的整合 * 定义person.jsp页面 姓名: * 创建PersonForm封装表单的数据(放置在cn.itcast.web.form下) public class PersonForm extends ActionForm {原创 2012-11-18 21:59:55 · 831 阅读 · 0 评论 -
利用jQuery完成全部选中,只要一个没选中全选按钮就不选中功能
test.html --> 选项1 选项2 选项3 选项4 选项5 全选 $("document").ready(function(){ $("input:eq(5)").click(function(){ if($(this).attr("checke原创 2012-11-06 22:51:43 · 3818 阅读 · 0 评论 -
正则表达式大全
验证数字的正则表达式集 验证数字:^[0-9]*$ 验证n位的数字:^\d{n}$ 验证至少n位数字:^\d{n,}$ 验证m-n位的数字:^\d{m,n}$ 验证零和非零开头的数字:^(0|[1-9][0-9]*)$ 验证有两位小数的正实数:^[0-9]+(.[0-9]{2})?$ 验证有1-3位小数的正实数:^[0-9]+(.[0-9]{1,3})?$ 验证非零原创 2012-09-04 20:44:01 · 834 阅读 · 0 评论 -
多线程操作单例设计模式的延迟加载(懒汉式)
class Single{ private Single(){} private static Single s=null; public static void method() { if (s==null) { synchronized(Single.class) { if(s==null) s=new Single(); } } r原创 2012-04-23 19:41:39 · 600 阅读 · 0 评论 -
当异常封装对象后再使用和不封装对象使用的区别
class Demo{ public static void main(String[] args) { try { /*showExce();*/ System.out.println("A"); } catch (Exception e) { System.out.println("B"); } finally { System.o原创 2012-04-22 17:47:44 · 563 阅读 · 0 评论 -
自定义除零异常!
class Demo{ int div(int a,int b)/*throws ArithmeticException*/ { if(b==0) throw new ArithmeticException("大爷的,你会不会啊!!!"); return a/b; }}class Demodemo9{ public static void main(Strin原创 2012-04-21 23:17:25 · 1073 阅读 · 0 评论 -
Map一对多映射!
import java.util.*;class MapDemo1{ public static void method1() { HashMap>czbk=new HashMap>(); ArrayListyure =new ArrayList(); ArrayListjiuye=new ArrayList(); czbk.put("yure",yure); czb原创 2012-04-30 20:56:28 · 1802 阅读 · 0 评论 -
不用迭代器,取出LinkedList集合中的所有元素。
import java.util.*;class LinkedListDemo{ public static void main(String[] args) { LinkedList l=new LinkedList(); l.addLast("java01"); l.addLast("java02"); l.addLast("java03"); l.addLast(原创 2012-04-28 13:37:25 · 2211 阅读 · 0 评论 -
用LinkedList集合模拟一个队列(先进先出)或者堆栈(先进后出)数据结构。
import java.util.*;class LinkedListTest1{ public static void main(String[] args) { DuiLie d=new DuiLie(); d.myAdd("java01"); d.myAdd("java02"); d.myAdd("java03"); d.myAdd("java04"); wh原创 2012-04-28 14:17:49 · 4363 阅读 · 1 评论 -
数组反转功能模拟
class ArrayFanZhuanDemo{ public static void main(String []args) { int arr[]={1,2,3,4,5,6,7,8,9}; for (int x=0,y=arr.length-1;x<y ; x++,y--) { arr[x]=arr[x]^arr[y]; arr[y]=arr[x]^arr[y];原创 2012-04-25 22:02:20 · 488 阅读 · 0 评论 -
常见异常
StringIndexOutOfBoundsException角标越界异常原创 2012-04-25 17:54:30 · 372 阅读 · 0 评论 -
if语句真正用法
class ZhenJiaDemo{ public static void main(String[] args) { if (false) { System.out.println("真在执行!!!"); } else { System.out.println("假在执行!!!!"); } }}//if只执行true语句!!!//else执行原创 2012-04-24 17:37:50 · 513 阅读 · 0 评论 -
往TreeSet中存入自定义对象,并且使用自定义排序方法(实现comparetor)
import java.util.*;class Person implements Comparable{ private String name; private int age; Person(String name,int age) { this.name=name; this.age=age; } public int getAge() { return a原创 2012-04-28 22:34:13 · 1180 阅读 · 0 评论 -
什么时候定义泛型类?
class Student{}class Worker{}class FanXing{ private XXC x; public void setFanXing(XXC x) { this.x=x; } public XXC getFanXing() { return x; }}class FanXingTest { public static voi原创 2012-04-29 20:24:13 · 827 阅读 · 0 评论 -
Map集合的两种取出方式
import java.util.*;class MapDemo{ public static void main(String[] args) { HashMapm=new HashMap(); m.put("001","xxc1"); m.put("002","xxc2"); m.put("003","xxc3"); Set>me=m.entrySet(); I原创 2012-04-30 14:47:01 · 657 阅读 · 0 评论 -
当泛型定义在接口上!!!
interface Inter{ /**/void show(T t);}class InterImpl implements Inter{ public /**/void show(/*T*/String t) { System.out.println(t); }}interface Inter1{ void show(T t);}class InterImp i原创 2012-04-29 21:43:47 · 672 阅读 · 0 评论 -
将泛型定义在类上和定义在接口上的区别!!!(包括静态)
class Demo{ public void show(T t) { System.out.println(t); } public void print(T t) { System.out.println(t); }}class Demo1{ public void show(T t) { System.out.println(t); } public原创 2012-04-29 21:19:00 · 1076 阅读 · 0 评论 -
多线程生产与消费
import java.util.concurrent.locks.*; class Demo { private String name; private String sex; private boolean flag=false; Lock lock=new ReentrantLock(); Condition condit原创 2012-04-28 19:45:40 · 635 阅读 · 0 评论 -
向HashSet集合存入对象,去除重复元素(覆写equals和hashCode方法)
import java.util.*;class Person{ private String name; private int age; Person(String name,int age) { this.age=age; this.name=name; } public int getAge() { return age; } public String原创 2012-04-28 19:40:18 · 1421 阅读 · 0 评论 -
向ArrayList集合中存入对象,并以让集合用自己设定的方式去除重复元素!(覆写equals方法)
import java.util.*;class Person{ private String name; private int age; Person(String name,int age) { this.name=name; this.age=age; } public void seName() { this.name=name; } public vo原创 2012-04-28 17:29:58 · 939 阅读 · 0 评论 -
Map练习!!!
/*每一个学生都有对应的归属地。学生Student,地址String.学生属性:姓名,年龄。注意:姓名和年龄相同的视为同一个学生。保证学生的唯一性。*/import java.util.*;class Student implements Comparable{ private String name; private int age; Student(String nam原创 2012-04-30 16:24:14 · 580 阅读 · 0 评论