定义接口:
package Bean.collections;
public interface Person {
public void useAxe();
}
package Bean.collections;
public interface Axe {
public String chop();
}
定义实现类:
package Bean.collections;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import Bean.collections.Person;
public class Chinese implements Person {
private List schools = new ArrayList();
private Map scores = new HashMap();
private Properties health = new Properties();
private Set axes = new HashSet();
public Set getAxes() {
return axes;
}
public void setAxes(Set axes) {
this.axes = axes;
}
public Properties getHealth() {
return health;
}
public void setHealth(Properties health) {
this.health = health;
}
public List getSchools() {
return schools;
}
public void setSchools(List schools) {
this.schools = schools;
}
public Map getScores() {
return scores;
}
public void setScores(Map scores) {
this.scores = scores;
}
public void useAxe() {
System.out.println("List --> " + schools);
System.out.println("Map --> " + scores);
System.out.println("Properties --> " + axes);
System.out.println("Set --> " + health);
}
}
package Bean.collections;
public class WoodAxe implements Axe {
public WoodAxe(String arg)
{
System.out.println("收到:"+arg);
}
public String chop() {
return "这是一把木头斧子";
}
public String toString() {
// TODO Auto-generated method stub
return "重写toString";
}
}
package Bean.collections;
public class SteelAxe implements Axe {
public String chop() {
return "这是一把铁斧子";
}
public String toString(){
return "重写toString";
}
}
Spring配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="chinese" class="Bean.collections.Chinese">
<property name="schools">
<list>
<value>小学</value>
<value>中学</value>
<value>大学</value>
</list>
</property>
<property name="health">
<props>
<prop key="血压">正常</prop>
<prop key="身高">178</prop>
</props>
</property>
<property name="scores">
<map>
<entry key="数学">
<value>88</value>
</entry>
<entry key="语文">
<value>99</value>
</entry>
</map>
</property>
<property name="axes">
<set>
<value>字符串斧子</value>
<!-- 用嵌套bean定义属性 -->
<bean class="Bean.collections.WoodAxe" >
<constructor-arg index="0">
<value>Hello,Spring!</value>
</constructor-arg>
</bean>
<!-- 引用bean作为属性 -->
<ref local="steelaxe" />
</set>
</property>
</bean>
<bean id="steelaxe" class="Bean.collections.SteelAxe"></bean>
</beans>
运行结果:
收到:Hello,Spring!
List --> [小学, 中学, 大学]
Map --> {数学=88, 语文=99}
Properties --> [字符串斧子, 重写toString, 重写toString]
Set --> {血压=正常, 身高=178}
分享到:
相关推荐
// java中对象容器主要有Set,List和Map三个接口类。 // 迭代器(Iterator)模式,又叫做游标(Cursor)模式。 // GOF给出的定义为:提供一种方法访问一个容器(container)对象中的各个元素, // 而又不需暴露该...
详解 Spring注解的(List&Map)特殊注入功能 最近接手一个新项目,已经没有原开发人员维护了。项目框架是基于spring boot进行开发。其中有两处Spring的注解花费了大量的时间才弄明白到底是怎么用的,这也涉及到...
Collection – 对象之间没有指定的顺序,允许重复元素。 Set – 对象之间没有指定的顺序,不允许重复元素 List– 对象之间有指定的顺序,允许重复元素,并引入位置...Map 接口既不继承 Set 也不继承 Collection。
spring,cxf,restful发布webservice传递复杂对象,例如List,Map,List<Map>
java集合类list-set-map.doc
//先实例化一个set Set<String> stringSet=new HashSet(); //向set里面添加元素 stringSet.add("123"); stringSet.add("wer"); stringSet.add("345"); //将set里的元素取出 Iterator<String> stringIter=...
Java集合排序及java集合类详解 (Collection, List, Set, Map)
一般使用springjdbc、hibernate的sql查询,库获取到的数据都是List<Map, Object>>结果集,如果我们要转化为JavaBean,则需要做一系列的map.get(),然后obj.set()。 此工程中就是解决List<Map, Object>>转化为...
List,set,Map 的用法和区别 List,set,Map 的用法和区别
java有关集合方面的总结 一目了然 绝对经典
实例主要讲述了,Spring的Xml(list,set,map)怎样进行注入值
详细描述map、list、set的常用子类特性,各个场景的适用。
自己写的例子,Java连接 redis 测试了string,list set ,map类型,以及中文测试,都正常,资源解释:http://www.cnblogs.com/aspirant/p/6816180.html
Spring实现集合(List_Map_Set)_自动装配,适合初学者熟悉集合类型的装配。
list map set联系与区别 list map set联系与区别 list map set联系与区别
Collection集合下,有List,Set这些接口,这些接口有哪些区别,什么情况下可以使用呢。Map集合该如何使用呢,如何遍历呢?
set,list,map区别与联系,很详细的介绍了区别和联系
java中list、set和map 的区别
javascript 模拟 java中的 List,Map js文件为 js/utils.js IE6.0 测试通过 <br>List: add(var obj) //添加一个元素 remove(var index) //删除一个元素 get(var index) //获取一个元素 remove...