//set集合
public Set
public void setSets(Set
this.sets = sets;
}
public CollectionBean() {
super();
System.out.println("========================");
}
//list集合
public List
public void setUsers(List
this.users = users;
}
//map集合
public Map
public void setMap(Map
this.map = map;
}
//props集合
public Properties props;
public void setProps(Properties props) {
this.props = props;
}
}
TestBean.java
[java]
package www.csdn.spring.collection.set;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestBean {
@Test
public void tests(){
ApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:spring-collection.xml");
CollectionBean bean = context.getBean("collectionBean",
CollectionBean.class);
System.out.println("---------------set----------------");
//获取set集合
Set
//得到迭代器
Iterator
//遍历
while (it.hasNext()){
System.out.println(it.next());
}
System.out.println("--------------list----------------");
List
for (User u : users) {
System.out.println(u.getName() + "-------------" + u.getAge());
}
System.out.println("----------------map1---------------");
//map1
Map
//得到map集合的key键值的set集合
Set
//得到key键值set集合的迭代器
Iterator
//迭代键值
while(itkeys.hasNext()){
//得到一个具体的键值
Integer key = itkeys.next();
//通过map集合的get(key)方法 获取key键值对应的value值
User user =map.get(key);
System.out.println(key+"------"+user.getName()+"-----"+"------"+user.getAge());
}
System.out.println("--------------map2--------------");
//map2
//获取实体对象的set集合
Set
//获取实体对象的迭代器
Iterator
//迭代
while(itentry.hasNext()){
//得到具体的Entry对象
Entry
//通过entry对象的getKey()和getValue得到
System.out.println(entry.getKey()+"----"+entry.getValue().getName()+"------"+entry.getValue().getAge());
}
System.out.println("--------------props-------------");
Properties props = bean.props;
//得到这个结合键值的key的set集合
Set
//String集合迭代器
Iterator
while(keystr.hasNext()){
//具体键值
String key = keystr.next();
//getProperty(key)获取key对应的value值
System.out.println(key