How to set Java Object into JaxBElement ? * In JaxBElement we are having setValue(T t) method. this will help us to solve this problem. * java.xml.bind.JAXBElement.setValue() Eg. Lets Use College Class as Bean. MainJaxBElement class as main class to process the College Class. package com.javavirus.jaxbelement; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class College{ private int id; private String name; public College(int id, String name) { super(); this.id = id; this.name = name; } public int getId() { return id; } @XmlAttribute public void setId(int id) { this.id = id; } public String getName() { return name; } @XmlElement public void setName(String name) { this.name = name; } @Override public String toString() { return "College [id=" + id + ", name=" + name + "]"...
Two Argument(Bi) Functional Interfaces - BiPredicate, BiFunction and BiConsumer * Predicate, Function and Consumer can access only one input values. * BiPredicate can access two input values. * BiFunction can access two input values. * BiConsumer can access two input values.
Bi Function: * When we need to access two input argument and we need to return some values, then we need to go for BiFunction. Syntax: interface BiFunction<T,U,R> { public R apply(T t,U u); //default method andThen() } Example: class Test { public static void main(String[] args) { BiFunction<Integer,Integer,Integer> f=(a,b)->a*b; System.out.println(f.apply(10,20)); System.out.println(f.apply(100,200)); } } Example: Create Student Object by taking name, roll no as input class Student { String name; int rollno; Student(String name,int rollno) { this.name=name; this.rollno=rollno; } } class Test { public static void main(String[] args) { ArrayList<Student> l = new ArrayList<Student>(); BiFunction<String,Integer,Student> f=(name,rollno)->new Student(name,rollno); l.add(f.apply("Durga",100)); l.add(f.apply("Ravi",200)); l.add(f.apply("Shiva",300)); l.add(f.apply(...
Comments
Post a Comment