Remove user object from a list
import java.util.List;
import java.util.ArrayList;
public class MainClass {
public static void main(String[] a) {
List<Employee> emps = new ArrayList<Employee>();
Employee emp1 = new Employee("A", "G");
Employee emp2 = new Employee("T", "A");
Employee emp3 = new Employee("K", "J");
emps.add(emp1);
emps.add(emp2);
emps.add(emp3);
System.out.println(emps);
emps.remove(emp2);
System.out.println(emps);
}
}
class Address {
}
class Employee {
private String lastName;
private String firstName;
private Double salary;
public Address address;
public Employee(String lastName, String firstName) {
this.lastName = lastName;
this.firstName = firstName;
this.address = new Address();
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public double getSalary() {
return this.salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Collection List:
- Create a list from an array
- Add element to a list at specified index
- Append one list to another list
- Insert a list at Specified Index
- Compare two List objects
- Convert Collection to List
- Convert a Queue to a List
- Convert List to array
- Convert List to a Set
- Copy List to Vector
- Copy one List to Another List
- Fill all elements in a list
- Fill n Copies of Specified Object
- Find maximum element in a List
- Find Minimum element in a List
- Get element by index
- Get Enumeration over List
- Get Synchronized List from a List
- Get Sub List
- Loop a list by Iterator
- Loop a list by generic Iterator
- Loop a list with using ListIterator
- Loop through a ist in reverse direction using ListIterator
- Remove an element by value and by index from List
- Remove all elements from a List
- Remove duplicate items from a List
- Remove item from a List while looping
- Remove range of elements from a List
- Remove user object from a list
- Replace an Element of List
- Replace all occurrences of specified element in a List
- Replace an element in a List using ListIterator
- Reverse a List
- Reverse order of all elements in a List
- Rotate elements of a list
- Search a List for an item with contains method
- Search elements of a List
- Binary Search a Sorted List
- Binary Search for a non-existent element in a List
- Set to change(replace) the value in a list
- Shuffle elements in a List
- Shuffle(repeatable) a List
- Sort a list
- Sort a List in descending order using comparator
- Swap elements of List