发表于: 2018-01-10 02:08:49

1 677


今天完成

1.复习昨天学习的Set集合和Map集合内容;

2.继续学习Map集合和Set集合;

  TreeSet和TreeMap的排序原理一样:

  自然排序:

package practice;

import java.util.TreeSet;
import java.util.Iterator;


   public  class person1 implements Comparable{
private String name;
      private int age;
      public person1(String name, int age){
super();
      this.name=name;
      this.age=age;
      }
public int compareTo(Object o){
person1 p=(person1)o;
          if (this.age>p.age)
return 1;
          if (this.age<p.age)
return -1;
          else
              return 0;
   }
public String getName() {
return name;
       }

public int getAge() {
return age;
       }


public static void main(String[] args) {
TreeSet ts = new TreeSet();
           ts.add(new person1("Jaime", 23));
           ts.add(new person1("Yolanda", 29));
           ts.add(new person1("Jorge", 27));
           ts.add(new person1("Rosa", 28));
           Iterator st = ts.iterator();
           while (st.hasNext()) {
person1 p = (person1) st.next();
               System.out.println(p.getName()+" "+p.getAge());
           }
}}

 客户化排序(明天自己尝试写一个

package practice2;

import java.util.*;
import java.util.Map.Entry;

class Demo3 {
public static void main(String[] args) {
TreeMap<Person, String> hm = new TreeMap<Person, String>(new MyComparator());
       hm.put(new Person("jack", 20), "1001");
       hm.put(new Person("rose", 18), "1002");
       hm.put(new Person("lucy", 19), "1003");
       hm.put(new Person("hmm", 17), "1004");
       hm.put(new Person("ll", 25), "1005");
       System.out.println(hm);
       System.out.println(hm.put(new Person("rose", 18), "1006"));

       Set<Entry<Person, String>> entrySet = hm.entrySet();
       Iterator<Entry<Person, String>> it = entrySet.iterator();
       while (it.hasNext()) {
Entry<Person, String> next = it.next();
           Person key = next.getKey();
           String value = next.getValue();
           System.out.println(key + " = " + value);
       }
}
}

class MyComparator implements Comparator<Person> {

@Override
   public int compare(Person p1, Person p2) {
if (p1.getAge() > p2.getAge()) {
return -1;
       } else if (p1.getAge() < p2.getAge()) {
return 1;
       }
return p1.getName().compareTo(p2.getName());
   }

}

class Person implements Comparable<Person> {
private String name;
   private int age;

   Person() {

}

public Person(String name, int age) {

this.name = name;
       this.age = age;
   }

public String getName() {
return name;
   }

public void setName(String name) {
this.name = name;
   }

public int getAge() {
return age;
   }

public void setAge(int age) {
this.age = age;
   }

@Override
   public int hashCode() {

return this.name.hashCode() + age * 37;
   }

@Override
   public boolean equals(Object obj) {
if (obj instanceof Person) {
Person p = (Person) obj;
           return this.name.equals(p.name) && this.age == p.age;
       } else {
return false;
       }
}

@Override
   public String toString() {

return "Person@name:" + this.name + " age:" + this.age;
   }

@Override
   public int compareTo(Person p) {

if (this.age > p.age) {
return 1;
       } else if (this.age < p.age) {
return -1;
       }
return this.name.compareTo(p.name);
   }


3.学习spring;

  1).spring的作用域:

2).spring的生命周期:当一个 bean 被实例化时,它可能需要执行一些初始化使它转换成可用状态。同样,当 bean 不再需要,并且从容器中移除时,可能需要做一些清除   工作。

     

 bean 的初始化 init-method 属性指定一个方法,在实例化 bean 时,立即调用该方法。

 bean 的销毁   destroy-method属性指定一个方法只有从容器中移除 bean 之后,才能调用该方法。

3).spring Bean 后置处理器

   回调方法这个概念不是太懂,知道这是什么,但是不知道其作用;

4).Bean 定义继承

当你使用基于 XML 的配置元数据时,通过使用父属性,指定父 bean 作为该属性的值来表明子 bean 的定义。(使用 parent 属性);

明天计划

1.学习spring—依赖注入;

2.学习并尝试写spring JDBC;

遇到问题

对一些概念性的名词感觉很模糊,需要更多时间查询资料理解定义;

收获

初步完成了集合类框架的学习;

学到了springIOC容器方面的知识点;



返回列表 返回列表
评论

    分享到