廖i雪

班级

TA还未加入任何班级

课程

2万+浏览/ 776学员/ 3.6评分
3万+浏览/ 1503学员/ 4.5评分
7536浏览/ 178学员/ 4.5评分

笔记

来自Java4Android 44 equals函数的作用(0)

class User{ String name; int age; public boolean equals(Object obj){  if(this == obj){    return true;  }  boolean b = obj instanceof User;  if(b){   User u = (User)obj;   if(this.age == u.age && this.name.equals(u.name)){    return true;   } else{    return false;   }  }  else{   return false;  } }}public class equals{ public static void main(String args[]){  User u1 = new User();  User u2 = new User();  User u3 = new User();  u1.name = "zhangsan";  u1.age = 12;  u2.name = "lisi";  u2.age = 12;  u3.name = "zhangsan";  u3.age = 12;  System.out.println(u1 == u3);  System.out.println(u1.equals(u2));  System.out.println(u1.equals(u3)); }}

来自Java4Android 38 Java中的线程-3(0)

class ThreadSync implements Runnable{ public void run(){ int i = 100; while(true){synchronized(this){ System.out.println(Thread.currentThread().getName() + i ); i--; Thread.yield(); if(i < 0){ break; }} } }public static void main(String args[]){ ThreadSync ts = new ThreadSync(); Thread t1 = new Thread(ts); Thread t2 = new Thread(ts); t1.setName("线程a"); t2.setName("线程b"); t1.start(); t1.yield(); t2.start(); }}

来自Java4Android 42 Java中类集框架-2(0)

//Java4Android 42 Java中的类集框架-2 //Collection接口import java.util.Set;import java.util.HashSet;import java.util.Iterator;//Iterator ← Collection ← Set ← HashSetpublic class Collection{ public static void main(String args[]){  HashSet<String> HashSet = new HashSet<String>();  Set<String> set = HashSet;//向上转型为set类  //Set<String> set = new HashSet<String>();  //set的add方法  int size = set.size();  System.out.println("add元素前集合长度为:" + size);//打印结果为0  //set的isEmpty方法  boolean b = set.isEmpty();  System.out.println("isEmpty:" + b);//打印结果为true  set.add("a");  set.add("b");  set.add("c");  set.add("d");    int i = set.size();  System.out.println("add元素后集合的长度:" + i);//打印结果为4    //set的remove方法  set.remove("b");  System.out.println("remove一个元素之后的长度:" + set.size());  //set的clear方法-清空集合内所有元素    //【迭代器】 Iterator接口遍历集合元素  Iterator it = set.iterator();  while(it.hasNext()){   System.out.println(it.next());  }    set.clear();  System.out.println("clear之后set size:" + set.size()); }}

留言

功能维护升级中,维护完成完后将再次开放,非常抱歉给您学习造成的不便。