- 博客(28)
- 资源 (4)
- 问答 (1)
- 收藏
- 关注
原创 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
原创 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 579
原创 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
原创 当泛型定义在接口上!!!
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
原创 将泛型定义在类上和定义在接口上的区别!!!(包括静态)
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
原创 什么时候定义泛型类?
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
原创 往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
原创 多线程生产与消费
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
原创 向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
原创 向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
原创 用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
原创 不用迭代器,取出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
原创 用迭代器取出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 3770
原创 数组反转功能模拟
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
原创 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
原创 多线程操作单例设计模式的延迟加载(懒汉式)
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
原创 易错点!!!
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
原创 当异常封装对象后再使用和不封装对象使用的区别
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
原创 自定义除零异常!
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
原创 手动抛出自定义异常!
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 929
原创 异常不可能全部同时发生
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
原创 补足代码
interface Inter { void method(); } class Test { static class Demo implements Inter { public void method() { System.out.println("哈哈哈哈");
2012-04-21 18:44:05 632
原创 匿名内部类
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
原创 当内部类定义在局部时
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
原创 多态的应用
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
原创 多态,接口
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
原创 多态
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
全年24小时运行的工控机选型
2023-01-18
java初学者小程序一枚不知哪里出错。
2012-04-08
TA创建的收藏夹 TA关注的收藏夹
TA关注的人