Java의 Stream of() 메소드

스트림(T t)

스트림(T t) 단일 요소를 포함하는 순차적 스트림을 반환합니다.
구문:

 static Stream of(T t) 

매개변수: 이 메소드는 필수 매개변수를 허용합니다. 이는 스트림의 단일 요소입니다.

반환 값: Stream of(T t)는 다음을 포함하는 순차 스트림을 반환합니다. 하나의 지정된 요소.

예 :




// Java code for Stream of(T t)> // to get a sequential Stream> // containing a single element.> > import> java.util.*;> import> java.util.stream.Stream;> > class> GFG {> > > // Driver code> > public> static> void> main(String[] args)> > {> > // Creating an Stream having single element only> > Stream stream = Stream.of(> 'Geeks'> );> > > // Displaying the Stream having single element> > stream.forEach(System.out::println);> > }> }>

산출:

 Geeks 

스트림(T… 값)

스트림(T… 값) 요소가 지정된 값인 순차적으로 정렬된 스트림을 반환합니다.

구문:

 static Stream of(T... values) 

매개변수: 이 메소드는 필수 매개변수를 허용합니다. 가치 이는 새 스트림의 요소입니다.

반환 값: Stream of(T… 값)은 요소가 지정된 값인 순차적으로 정렬된 스트림을 반환합니다.

예:




// Java code for Stream of(T... values)> // to get a sequential ordered stream whose> // elements are the specified values.> > import> java.util.*;> import> java.util.stream.Stream;> > class> GFG {> > > // Driver code> > public> static> void> main(String[] args)> > {> > // Creating an Stream> > Stream stream = Stream.of(> 'Geeks'> ,> 'for'> ,> 'Geeks'> );> > > // Displaying the sequential ordered stream> > stream.forEach(System.out::println);> > }> }>

산출:

 Geeks for Geeks