Find Customer staring with +91 mobile number
Categories: Java 8(JDK1.8) Java Java Examples
Find Customer staring with +91 mobile number
package r4r.co.in;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class FindCustomerStartingWithMobileNumberExample {
public static void main(String[] args) {
// Find Customer staring with +91 mobile number
List<Customer> list = new ArrayList<Customer>();
list.add(new Customer("+917042316824", "Rajesh Kumar"));
list.add(new Customer("+917042316823", "Rahul Kumar"));
list.add(new Customer("+927042316825", "Raohit Kumar"));
list.add(new Customer("+917042316826", "Shiv Kumar"));
List<Customer> outputList = list.stream().filter(e -> e.getNumber().startsWith("+91"))
.collect(Collectors.toList());
System.out.println(outputList);
}
}
class Customer {
private String number;
private String name;
public Customer(String number, String name) {
super();
this.number = number;
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Customer [number=" + number + ", name=" + name + "]";
}
}