Iterate List based on condition Set Values to another object - java

Iterate List based on condition Set Values to another object using Java 8?
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Demo {
public static void main(String[] args) {
// TODO: Condition is => Only if id = 100, then assign internalMarks to (externalMarks + internalMarks); to 103
// So internalMarks = 0 and externalMarks = 500+250=750
List<Employee> employees = Arrays.asList(
new Employee(100, 500, "John", 250),
new Employee(101, 500, "Jane", 250),
new Employee(102, 500, "Jack", 250),
new Employee(103, 500, "Mike", 250)
);
List<Employee> newList = new ArrayList<>();
employees.stream().forEach(e -> {
if(e.getId() == 100 && e.getId() > 0) {
e.setExternalMark(0);
newList.add(e);
}else {
newList.add(e);
}
});
System.out.println(newList);
}
static class Employee {
private int id;
private int internalMark;
private String name;
private int externalMark;
public Employee() {
}
public Employee(int id, int internalMark, String name, int externalMark) {
super();
this.id = id;
this.internalMark = internalMark;
this.name = name;
this.externalMark = externalMark;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getInternalMark() {
return internalMark;
}
public void setInternalMark(int internalMark) {
this.internalMark = internalMark;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getExternalMark() {
return externalMark;
}
public void setExternalMark(int externalMark) {
this.externalMark = externalMark;
}
#Override
public String toString() {
return "Employee [id=" + id + ", internalMark=" + internalMark + ", name=" + name + ", externalMark="
+ externalMark + "]";
}
}
}

//Condition is => Only if id = 100, then assign internalMarks to (externalMarks + internalMarks); to 103
// So internalMarks = 0 and externalMarks = 500+250=750
From your condition, as its slighlty unclear that externalMarks should be changes for Id=100 or Ids 100 to 103, means for all Employees
Take one scenario, where externalMarks should be changes for id = 100, then solution can be
List<Employee> newList1 = employees.stream()
.map(e-> {
if(e.getId() == 100) {
e.setExternalMark(e.getInternalMark()+e.getExternalMark());
e.setInternalMark(0);
}
return e;
})
.collect(Collectors.toList());
For other scenario, where externalMarks should be changes for id = 100 to 103, then solution can be
List<Employee> newList1 = employees.stream()
.map(e-> {
e.setExternalMark(e.getInternalMark()+e.getExternalMark());
e.setInternalMark(0);
return e;
})
.collect(Collectors.toList());

Related

Internal working of Tree Set Or Difference between HashSet and TreeSet

For TreeSet Sorting for mutable object :
If I don't override hashcode equals then for an object having same value for all the fields will be treated as two different object in set as( default objects class hashcode method calculate the hash value of the memory locatuion). So why it is different for the TreeSet. See the below Example.
If I just copy a whole Set into a treeSet then why sorting is not happning.
.
public class Student {
private int id;
private String name;
private int marks;
public Student(int id, String name, int marks) {
super();
this.id = id;
this.name = name;
this.marks = marks;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMarks() {
return marks;
}
public void setMarks(int marks) {
this.marks = marks;
}
#Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", marks=" + marks + "]";
}
public static Comparator<Student> idComparator = new Comparator<Student>() {
#Override
public int compare(Student o1, Student o2) {
return (new Integer(o1.getId())).compareTo(o2.getId());
}
};
public static Comparator<Student> nameComparator = new Comparator<Student>() {
#Override
public int compare(Student o1, Student o2) {
return o1.getName().compareTo(o2.getName());
}
};
/*#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + marks;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Student other = (Student) obj;
if (id != other.id)
return false;
if (marks != other.marks)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}*/
}
.
public class TestMain {
public static void main(String[] args) {
Student s1 = new Student(1, "A", 50);
Student s2 = new Student(1, "A", 50);
Student s3 = new Student(2, "B", 51);
Student s4 = new Student(3, "B", 51);
Student s5 = new Student(4, "B", 41);
Student s6 = new Student(5, "B", 61);
Student s7 = new Student(6, "C", 51);
Student s8 = new Student(7, "D", 46);
Student s9 = new Student(8, "B", 55);
Student s10 = new Student(9, "E", 51);
List<Student> studentList = new ArrayList<>();
studentList.add(s1);
studentList.add(s2);
studentList.add(s3);
studentList.add(s4);
studentList.add(s5);
studentList.add(s6);
studentList.add(s7);
studentList.add(s8);
studentList.add(s9);
studentList.add(s10);
studentList.add(s1);
studentList.add(s2);
studentList.add(s3);
studentList.add(s4);
System.out.println("List Initial Size: " + studentList.size());
List<Student> studentListAfterFilter = studentList.stream()
.filter(p -> p.getMarks() >= 45 && p.getMarks() <= 55).map(p -> p).collect(Collectors.toList());
System.out.println("After filtering List Size: " + studentListAfterFilter.size());
Set<Student> studentSetAfterFilter = studentList.stream().filter(p -> p.getMarks() >= 45 && p.getMarks() <= 55)
.map(p -> p).collect(Collectors.toSet());
System.out.println("After filtering Set Size: " + studentSetAfterFilter.size());
for(Student student:studentSetAfterFilter){
System.out.println("Set Objects: "+student.toString());
}
Set<Student> studentTreeSetAfterFilter=new TreeSet<>(Student.nameComparator);
studentTreeSetAfterFilter.add(s1);
studentTreeSetAfterFilter.add(s2);
studentTreeSetAfterFilter.add(s3);
studentTreeSetAfterFilter.add(s4);
studentTreeSetAfterFilter.add(s5);
studentTreeSetAfterFilter.add(s6);
studentTreeSetAfterFilter.add(s7);
studentTreeSetAfterFilter.add(s8);
studentTreeSetAfterFilter.add(s9);
studentTreeSetAfterFilter.add(s10);
studentTreeSetAfterFilter.add(s1);
studentTreeSetAfterFilter.add(s2);
studentTreeSetAfterFilter.add(s3);
studentTreeSetAfterFilter.add(s4);
for(Student student:studentTreeSetAfterFilter){
System.out.println("TreeSet Objects: "+student.toString());
}
}
}

split List of values based on value

I have a list of objects(Person in this case) and I want to split them into a list of list Person objects based on value. In the example given below, I have a Person object with name, id and Address object. The address object has a house number, Street Id. Now I want to split them based on Street Id in address object using collections API. I tried grouping by, partitioning in collections, but couldn't get it work. I want to use only Java 8. No third party.
Expected result :
[ [person1, person2, person3] , [person4, person5], [person6] ]
Thanks.
package testapplication2;
import java.util.ArrayList;
import java.util.List;
/**
*
*
*/
public class JavaCollections {
public static void main(String[] args) {
JavaCollections c = new JavaCollections();
c.test1();
}
public void test1() {
List<Person> persons = new ArrayList<>();
Address address1 = new Address(1, "X Street", 100);
Address address2 = new Address(2, "X Street", 100);
Address address3 = new Address(3, "X Street", 100);
Address address4 = new Address(4, "Y Street", 101);
Address address5 = new Address(5, "Y Street", 101);
Address address6 = new Address(6, "Z Street", 102);
persons.add(new Person(1, "P1", address1));
persons.add(new Person(2, "P2", address2));
persons.add(new Person(3, "P3", address3));
persons.add(new Person(4, "P4", address4));
persons.add(new Person(5, "P5", address5));
persons.add(new Person(6, "P6", address6));
}
public class Person {
public int personId;
private String name;
private Address address;
public Person() {
}
public Person(int personId, String name, Address address) {
super();
this.personId = personId;
this.name = name;
this.address = address;
}
public int getPersonId() {
return personId;
}
public void setPersonId(int personId) {
this.personId = personId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
#Override
public String toString() {
return "Person{" + "personId=" + personId + ", name=" + name + ", address=" + address + '}';
}
}
public class Address {
public Address() {
}
public Address(int houseNumber, String streetName, int streetId) {
this.houseNumber = houseNumber;
this.streetId = streetId;
this.streetName = streetName;
}
private int houseNumber;
private String streetName;
private int streetId;
public int getHouseNumber() {
return houseNumber;
}
public void setHouseNumber(int houseNumber) {
this.houseNumber = houseNumber;
}
public String getStreetName() {
return streetName;
}
public void setStreetName(String streetName) {
this.streetName = streetName;
}
public int getStreetId() {
return streetId;
}
public void setStreetId(int streetId) {
this.streetId = streetId;
}
#Override
public String toString() {
return "Address{" + "houseNumber=" + houseNumber + ", streetName=" + streetName + ", streetId=" + streetId + '}';
}
}
}
This should do it:
List< List<Person> > groups = new ArrayList<>( persons.stream().collect(
Collectors.groupingBy( p -> p.getAddress().getStreetId() ) ).values() );
Alternatively by #shmosel:
List< List<Person> > groups = persons.stream().collect( Collectors.collectingAndThen(
Collectors.groupingBy( p -> p.getAddress().getStreetId() ),
m -> new ArrayList<>( m.values() ) ) );
The solution for your requirement is the usage of stream().collect() with a groupingBy call on the person.address.streetId field as a key.
This code should do it:
final List<List<Person>> groupedPersons = persons.stream()
.collect(Collectors.groupingBy(o -> o.address.streetId))
.entrySet().stream()
.map(Map.Entry::getValue).collect(Collectors.toList());
// Code for printing out
groupedPersons.forEach(people -> {
System.out.print("[");
System.out.print(people.stream().map(person -> String.format("person%d", person.personId)).collect(Collectors.joining(",")));
System.out.print("]");
});
Here is a full example which you can run:
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Partitions {
public static void main(String[] args) {
List<Person> persons = new ArrayList<>();
Address address1 = new Address(1, "X Street", 100);
Address address2 = new Address(2, "X Street", 100);
Address address3 = new Address(3, "X Street", 100);
Address address4 = new Address(4, "Y Street", 101);
Address address5 = new Address(5, "Y Street", 101);
Address address6 = new Address(6, "Z Street", 102);
persons.add(new Person(1, "P1", address1));
persons.add(new Person(2, "P2", address2));
persons.add(new Person(3, "P3", address3));
persons.add(new Person(4, "P4", address4));
persons.add(new Person(5, "P5", address5));
persons.add(new Person(6, "P6", address6));
final List<List<Person>> groupedPersons = persons.stream()
.collect(Collectors.groupingBy(o -> o.address.streetName))
.entrySet().stream()
.map(Map.Entry::getValue).collect(Collectors.toList());
groupedPersons.forEach(people -> {
System.out.print("[");
System.out.print(people.stream().map(person -> String.format("person%d", person.personId)).collect(Collectors.joining(",")));
System.out.print("]");
});
}
public static class Person {
public int personId;
private String name;
private Address address;
public Person() {
}
public Person(int personId, String name, Address address) {
super();
this.personId = personId;
this.name = name;
this.address = address;
}
public int getPersonId() {
return personId;
}
public void setPersonId(int personId) {
this.personId = personId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
#Override
public String toString() {
return "Person{" + "personId=" + personId + ", name=" + name + ", address=" + address + '}';
}
}
public static class Address {
private int houseNumber;
private String streetName;
private int streetId;
public Address() {
}
public Address(int houseNumber, String streetName, int streetId) {
this.houseNumber = houseNumber;
this.streetId = streetId;
this.streetName = streetName;
}
public int getHouseNumber() {
return houseNumber;
}
public void setHouseNumber(int houseNumber) {
this.houseNumber = houseNumber;
}
public String getStreetName() {
return streetName;
}
public void setStreetName(String streetName) {
this.streetName = streetName;
}
public int getStreetId() {
return streetId;
}
public void setStreetId(int streetId) {
this.streetId = streetId;
}
#Override
public String toString() {
return "Address{" + "houseNumber=" + houseNumber + ", streetName=" + streetName + ", streetId=" + streetId + '}';
}
}
}
This will print out:
[person4,person5][person6][person1,person2,person3]
Update:
If you want to preserve the order in which it was added to the initial list, you can provide a collector which supplies a java.util.LinkedHashSet - a data structure which preserves uniqueness and the original order of insertion.
The grouping code would look like this:
final List<Set<Person>> groupedPersons = persons.stream()
.collect(Collectors.groupingBy(o -> o.address.streetId,
Collector.of(() -> new LinkedHashSet<Person>(), HashSet::add, (s1, s2) -> {
s1.addAll(s2);
return s1;
})))
.entrySet().stream()
.map(Map.Entry::getValue).collect(Collectors.toList());
If you use this code in the example above it will print out:
[person1,person2,person3][person4,person5][person6]
To achieve this, you need to
use a Stream of your list,
then groupBy the id of the Address, all the Person with the same adressId will be together in a Map<Integer,List<Person>>
then you get the values (all the List<Person> and collecth them together)
public static void main(String[] args) {
JavaCollections c = new JavaCollections();
List<Person> persons = c.test1();
List<List<Person>> res = new ArrayList<>(persons .stream()
.collect(Collectors.groupingBy(o -> o.getAddress().getStreetId())).values());
System.out.println(test);
}
And change test1() to
public static List<Person> test1() {
...;
return persons;
}
to return the list

How to sort by more than one property of an object - linq4j

I am using linq4j. I am only sorting by one property and would like to sort by multiple property. If is is not supported in linq4j than what other method I can use. Following is my code snippet,
import java.util.Arrays;
import java.util.List;
import net.hydromatic.linq4j.Linq4j;
import net.hydromatic.linq4j.function.*;
public class Linq4jExample {
public static class Employee {
public final int empno;
public final String name;
public final int deptno;
public Employee(int empno, String name, int deptno) {
this.empno = empno;
this.name = name;
this.deptno = deptno;
}
public String toString() {
return "Employee(empno: " + empno +",name: " + name + ", deptno:" + deptno + ")";
}
}
public static final Employee[] emps = {
new Employee(100, "Fred", 10),
new Employee(110, "Bill", 30),
new Employee(120, "Bill", 10),
new Employee(120, "Eric", 12),
new Employee(130, "Janet", 13),
};
public static final Function1<Employee, Integer> EMP_DEPTNO_SELECTOR =
new Function1<Employee, Integer>() {
public Integer apply(Employee employee) {
return employee.deptno;
}
};
public static void main(String[] args) {
List<Employee> filter=Linq4j.asEnumerable(Arrays.asList(emps))
.orderBy(new Function1<Employee,String>()
{
public String apply(Employee arg0)
{
return arg0.name;
}
}).toList();
}
}
A potential use case could be sorting by department number and then by name
You can have multiple order by in linq4j. Check the following example
package maven_lab;
import java.util.Arrays;
import java.util.List;
import org.apache.calcite.linq4j.Linq4j;
import org.apache.calcite.linq4j.function.Function1;
public class Linq4jExample {
public static final Employee[] emps = {
new Employee(100, "Fred", 10),
new Employee(110, "Bill", 30),
new Employee(120, "Bill", 10),
new Employee(120, "henry", 10),
new Employee(120, "Adam", 10),
new Employee(120, "Eric", 12),
new Employee(130, "Janet", 13),
};
public static final Function1<Employee, Integer> EMP_DEPTNO_SELECTOR =
new Function1<Employee, Integer>() {
public Integer apply(Employee employee) {
return employee.deptno;
}
};
public static void main(String[] args) {
List<Employee> filter = Linq4j.asEnumerable(Arrays.asList(emps)).orderBy(e -> e.deptno)
.orderBy(e -> e.name).toList();
System.out.println(filter);
}
public static class Employee {
public final int empno;
public final String name;
public final int deptno;
public Employee(int empno, String name, int deptno) {
this.empno = empno;
this.name = name;
this.deptno = deptno;
}
public String toString() {
return "Employee(empno: " + empno + ",name: " + name + ", deptno:" + deptno + ")";
}
}
}
Notice that I am ordering by department first and then the name. You should also use jdk8 lambda instead of anonymous classes.
Pre JDK8 you can do this like following,
List<Employee> filter = Linq4j.asEnumerable(Arrays.asList(emps)).orderBy(new Function1<Employee, Integer>() {
public Integer apply(Employee arg0) {
return arg0.deptno;
}
}).orderBy(new Function1<Employee, String>() {
public String apply(Employee arg0) {
return arg0.name;
}
}).toList();

Sort ArrayList of objects by field in custom order

How can I achieve a custom sorting to the content of field name:
first element: P followed by numbers [1-9]{2} always on first
followed by : P followed by numbers 0[0-9]
followed by : S
followed by numbers [1-9]{2}
and then the rest in normal order i1.getName().compareToIgnoreCase(i2.getName())
private static Comparator<Item> itemComperator = new Comparator<Item>() {
#Override
public int compare(Item i1, Item i2) {
if (i1.getName().matches("P[1-9]{2}") && i2.getName().matches("P0[0-9]"))
return -1;
else if (i1.getName().matches("S[1-9]{2}"))
return -1;
else
return i1.getName().compareToIgnoreCase(i2.getName());
}
};
#Test
public void sortItem() {
Item item01 = new Item(1, "R59");
Item item02 = new Item(2, "S48");
Item item03 = new Item(3, "P01");
Item item04 = new Item(4, "P25");
Item item05 = new Item(5, "R99");
List<Item> items = Arrays.asList(item01, item02, item03, item04, item05);
System.out.println("before sorting");
long seed = System.nanoTime();
Collections.shuffle(items, new Random(seed));
for (Item i : items) {
System.out.println(i.getId() + " " + i.getName());
}
System.out.println("after sorting");
Collections.sort(items, itemComperator);
for (Item i : items) {
System.out.println(i.getId() + " " + i.getName());
}
}
public class Item {
private int id;
private String name;
public Item(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
output expected:
after sorting
4 P25
3 P01
2 S48
1 R59
5 R99
I think that I would first map each of the inputs to a "kind" number, which is based upon the list of criteria above. For example:
int kind(String input) {
if (input.matches("P[1-9]{2}") {
return 0;
} else if (input.matches("P0[0-9]")) {
return 1;
} else if (input.matches("S.*")) {
return 2;
} else if (input.matches("[1-9]{2}")) {
return 3;
} else {
return 4;
}
}
This gives you a way to see if the two strings are of the same "kind"; if not, return the ordering based on the kind. If they are the same kind, just compare them using (case insensitive) lexicographic ordering (you don't specify, but I assume you want e.g. "P11" to come before "P22"):
public int compare(Item a, Item b) {
String nameA = a.getName();
String nameB = b.getName();
int kindA = kind(nameA);
int kindB = kind(nameB);
if (kindA != kindB) {
return Integer.compare(kindA, kindB);
} else {
return nameA.compareToIgnoreCase(nameB);
}
}

Generating sequence numbers in Java from the ArrayList

How to generate sequence numbers and assign them to each object in java?
for example i have the following,
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class MyMaxUDOComparable
{
public static Integer findMaxScore(List<testVO> emps)
{
Integer maxScoreTotal = 0;
for (Iterator<JobFitSurveyConfigVO> iterator = emps.iterator(); iterator.hasNext();)
{
testVOempl = (testVO) iterator.next();
if (empl != null)
{
maxScoreTotal += empl.getSalary();
}
}
return maxScoreTotal;
}
public static void main(String a[])
{
List<testVO> emps = new ArrayList<testVO>();
emps.add(new testVO(10, "Raghu", 10,1));
emps.add(new testVO(120, "Krish", 10,2));
emps.add(new testVO(210, "John", 10,3));
emps.add(new testVO(150, "Kishore", 10,4));
testVOmaxSal = Collections.max(emps);
System.out.println("Employee with max Id: " + maxSal);
System.out.println("maxScoreTotal: " + findMaxScore(emps));
}
}
class testVOimplements Comparable<testVO>
{
private Integer id;
private String name;
private Integer salary;
private Integer sequenceNumber;
public testVO(Integer id, String name, Integer sal,Integer sequenceNumber) {
this.id = id;
this.name = name;
this.salary = sal;
}
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Integer getSalary()
{
return salary;
}
public void setSalary(Integer salary)
{
this.salary = salary;
}
public Integer getSequenceNumber()
{
return sequenceNumber;
}
public void setSequenceNumber(Integer sequenceNumber)
{
this.sequenceNumber = sequenceNumber;
}
#Override
public int compareTo(JobFitSurveyConfigVO emp)
{
return this.id.compareTo(emp.getId());
}
public String toString()
{
return id + " " + name + " " + salary;
}
}
in the above class, i have assigned values to all the objects for Sequence Number and if I remove any object from the list then the Sequence Number has to be re generated.
how to do this in java, would some one help me on this please?.
public void deleteObjFormList(JobFitSurveyConfigVO emp,List<JobFitSurveyConfigVO> emps)
{
int i = emps.indexOf(emp);
emps.remove(i);
for(int j=i;j<emps.size();j++)
{
JobFitSurveyConfigVO emp1 = emps.get(j);
emp1.setSequenceNumber(emp1.getSequenceNumber()-1);
}
return;
}
I this this should be a function to remove the object from the list.
You iterate the list and set the sequence number.
Be aware that your constructor is not assigning the sequence number, so although you provided values, they are all null. If you changed type to the more sensible int, they would be 0.
// Renumber (aka resequence) the emp records
for (int i = 0; i < emps.size(); i++)
emps.get(i).setSequenceNumber(i + 1);
try this way
public static void main(String a[]) {
List<JobFitSurveyConfigVO> emps = new ArrayList<JobFitSurveyConfigVO>();
ArrayList<Integer> seq = new ArrayList<Integer>();
addElement(seq, emps, 10, "Raghu", 10);
addElement(seq, emps, 120, "Krish", 10);
addElement(seq, emps, 210, "John", 10);
addElement(seq, emps, 150, "Kishore", 10);
System.out.println("Display : "+emps);
removeElement(2, seq, emps);
System.out.println("Removed : "+emps);
addElement(seq, emps, 210, "John2", 10);
System.out.println("Added : "+emps);
}
Add Element and Remove Element methods
public static void addElement(ArrayList<Integer> seq,
List<JobFitSurveyConfigVO> emps, int id, String name, Integer salary) {
int size = seq.size();
Collections.sort(seq); // Make sure they are in Sequence.
if (size > 1) {
for (int i = 1; i < size; i++) {
int check = seq.get(i-1);
if ( (check + 1) != (seq.get(i))) {
seq.add(check + 1);
emps.add(new JobFitSurveyConfigVO(id, name, salary, (check + 1)));
break;
}
if (i+1 == size) {
seq.add(seq.get(i) + 1);
emps.add(new JobFitSurveyConfigVO(id, name, salary, (seq.get(i) + 1)));
}
}
}else if (size == 1 && seq.get(0) == 1) {
int check = seq.get(0);
seq.add(check + 1);
emps.add(new JobFitSurveyConfigVO(id, name, salary, (check + 1)));
}else{
seq.add(1);
emps.add(new JobFitSurveyConfigVO(id, name, salary, 1));
}
}
public static void removeElement(int index, ArrayList<Integer> seq, List<JobFitSurveyConfigVO> emps){
if (index < seq.size()) {
emps.remove(index);
seq.remove(index);
}else {
throw new ArrayIndexOutOfBoundsException();
}
}
constructor
public JobFitSurveyConfigVO(Integer id, String name, Integer sal,Integer sequenceNumber) {
this.id = id;
this.name = name;
this.salary = sal;
this.sequenceNumber = sequenceNumber;
}

Categories