Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java streams

the Stream API is used to process collections
of objects. A stream is a sequence of objects
that supports various methods which can be
pipelined to produce the desired result.
  It is very similar to build().perform() 
  method in Actions class. It is chaining
  some operations in an order.

The features of Java stream are:
- A stream is not a data structure instead
it takes input from the Collections, 
Arrays or I/O channels.
- Streams don’t change the original data
structure, they only provide the result
as per the pipelined methods.
- Each intermediate operation is lazily
executed and returns a stream as a result,
hence various intermediate operations
can be pipelined. Terminal operations mark
the end of the stream and return the result.

Different Operations On Streams:

map ==> The map method is used to return a
stream consisting of the results of applying
the given function to the elements of this stream.
List number = Arrays.asList(2,3,4,5);
List square = number.stream().map(x->x*x).collect(Collectors.toList());

filter ==> The filter method is used to
select elements as per the Predicate passed as argument.
List names = Arrays.asList("Reflection","Collection","Stream");
List result = names.stream().filter(s->s.startsWith("S")).collect(Collectors.toList());

sorted ==> The sorted method is used to sort the stream.
List names = Arrays.asList("Reflection","Collection","Stream");
List result = names.stream().sorted().collect(Collectors.toList());

ArrayList<String> list3 = new ArrayList(Arrays.asList("monkey", "donkey","onion"));
List<String> list4 = list3.stream().filter(each->!"onion".equals(each)).collect(Collectors.toList());
System.out.println(list4);

static String reverse(String word){
    return Arrays.stream(word.split("")).reduce("", (x,y) -> y+x );
}
Comment

java streams

Arrays.asList("a1", "a2", "a3")
    .stream()
    .findFirst()
    .ifPresent(System.out::println);  // a1
Comment

PREVIOUS NEXT
Code Example
Java :: how to set id to TextView programmatically java android 
Java :: x^n+y^n=z^n 
Java :: pyqt tree view 
Java :: java schleife abbrechen 
Java :: initialize generic array java 
Java :: declare a variable java 
Java :: inputstream to bufferedreader 
Java :: java destroy object 
Java :: save logs tomcat java spring boot 
Java :: Java Static Top-level Class 
Java :: buffered reader for big integer 
Java :: public class HelloWorld { public static void main( String[] argv ) { int a=4%2*3-1/0; System.out.println(a); } } 
Java :: run java bytecode 
Java :: constructors in java 
Java :: how to get column and row numbers in java 
Java :: check if object is a string java 
Java :: ex: Overflow in java 
Java :: get historical data from the past to the present yahoo finance api 
Java :: java change time to hh:mm:ss format 
Java :: JAVA XML COURSE 
Java :: java array k&uuml;rzen 
Java :: what is serialization and deserialization in rest assured 
Java :: hollow rectangle pattern in java 
Java :: quick select method for kth smallest element in java 
Java :: android studio cannot resolve @nullable 
Java :: How to handle exceptions thrown by application with another servlet? 
Java :: python to java code conversion 
Java :: concludes() Method 
Java :: testng with cucumber 
Java :: java digit in number 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =