Commit 4495a011 authored by Suresh Kumar's avatar Suresh Kumar

Set Formate

parent 2ff96754
package CreateStream;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
public class CreateStream {
public static void main (String [] args){
List<Integer> list1 = new ArrayList<>();
list1.add(1);
list1.add(2);
//#1) Create Stream Using stream() Method
Stream <Integer> newList = list1.stream();
//#2) Create Stream Using stream() Method
Stream <Object> emptyStream = Stream.empty();
//#3) Create Stream Using stream() Method
String names [] = {"Suresh Kumar" , "Rayyan Hassan", "Asad Iqbal"};
Stream <String> newSteam = Stream.of(names);
//#4) Create Stream Using stream() Method
Stream <Object> streamBuilder = Stream.builder().build();
System.out.println("Only Streams Created...........!!");
}
}
package StreamFilterFunction;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class FiltrProduct {
public static void main(String [] args){
List<Product> productsList = new ArrayList<Product>();
productsList.add(new Product(1, "MacBook Pro",400000));
productsList.add(new Product(2, "HP Laptop", 100000));
productsList.add(new Product(3,"Dell", 86000));
productsList.add(new Product(4, "Lenovo", 70000));
List<Float> productprice = productsList.stream().filter(e->e.price>70000).map(e->e.price).collect(Collectors.toList());
System.out.println(productprice);
String name [] = {"Suresh" , "Arsam" , "Rahim"};
Stream<String> stream1 = Stream.of(name);
// List<String> names = stream1.filter(e->e.startsWith("S ")).collect(Collectors.toList());
List<String> names = stream1.filter(e->e.endsWith("h")).collect(Collectors.toList());
System.out.println(names);
Integer number [] = {1 , 2 , 3, 4, 7, 9, 10};
Stream<Integer> newNumbers = Stream.of(number);
List <Integer> newNum = newNumbers.map(i->i*i).collect(Collectors.toList());
System.out.println(newNum);
System.out.println("Stream Filter..............!!");
}
}
package StreamFilterFunction;
public class Product {
private int id;
private String name;
float price;
public Product(int id , String name, float price){
this.id =id;
this.name=name;
this.price = price;
}
}
package StreamForEach;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class StreamForEach {
public static void main (String [] args){
List<Integer> list1 = new ArrayList<>();
list1.add(1);
list1.add(2);
list1.add(3);
list1.add(5);
Stream<Integer> list = list1.stream();
List<Integer> newlist = list.filter(e->e%2==0).collect(Collectors.toList());
System.out.println(newlist);
String names [] = {"Suresh Kumar" , "Rayyan Hassan", "Asad Iqbal"};
Stream <String> newSteam = Stream.of(names);
newSteam.forEach(e->{
System.out.println(e);
});
System.out.println("Streams ForEach...........!!");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment