2:08 am - Saturday January 21, 2017

Spring Collection set Example Program in Eclipse

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Project  Structure

Jar Files

How To Add Jar Files:

 spring-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
	<bean id="stringId" class="java.lang.String">
		<constructor-arg>
			<value>Mathan</value>
		</constructor-arg>
	</bean>
	<bean id="student" class="com.candidjava.Student">

		<property name="studentSet">
			<set>
				<value>Deepa</value>
				<value>Deepa</value>
				<ref local="stringId" />
				<value>Kalai</value>
			</set>
		</property>

	</bean>
</beans>



Student.java

package com.candidjava;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class Student {

	private Set studentSet = null;

	public void setStudentSet(Set studentSet) {
		this.studentSet = studentSet;
	}

	public Set getStudentSet() {
		return studentSet;
	}
}

StudentMain.java

package com.candidjava;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class StudentMain {
	public static void main(String a[]) {

		BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
				"config\\spring-config.xml"));
		Student student = (Student) factory.getBean("student");

		HashSet studentSet = (HashSet) student.getStudentSet();
		TreeSet ts = new TreeSet();
		ts.addAll(studentSet);
		Iterator iterator1 = ts.iterator();
		System.out.println("Set example in Spring");
		System.out.println();
		while (iterator1.hasNext()) {
			Object obj = iterator1.next();

			System.out.println(obj);
			System.out.println();
		}

	}

}

 OUTPUT

DOWNLOAD+SOURCE CODE+JAR FILES

Filed in: Z-A Spring Codes

Comments are closed.