To convert a wrapper type array string[], integer[], etc. to a basic type array such as int[], is to use the Java8 stream for a for loop.
public class Tostreamintstring{public static void Main (string[] args) {Scanner in = new Scanner (system.in); list<string> list = new arraylist<> (); for (int i = 0; i < 3; i++) {List.add (In.nextline ());} String n = list.get (0); System.out.println ("\ n---> string\n" +n); string[] xs = list.get (1). Split ("\\s+"); string[] ys = List.get (2). Split ("\\s+"); System.out.println ("\ n---> string[] to int[]");
You need to enter a pure digital int[] x = Arrays.stream (xs). Maptoint (integer::valueof). ToArray (); Arrays.stream (x). ForEach ((i)-System.out.print (i+ "")); System.out.println ("\ n---> string[] to list, list to Stream"); List<string> y = arrays.aslist (ys), Y.stream (). ForEach ((i) System.out.print (i+ "")); In.close ();}}
Java8 stream can be obtained in many ways, in which the stream () method can be used directly to the collection class, and the source code can be seen to know that the collection interface has a new default method Stream<e> stream (),
The Java Collection class is able to use the stream () method to get the stream.
Public interface Collection<e> extends iterable<e> { /** * @since 1.8 */ default Stream <E> Stream () { return Streamsupport.stream (Spliterator (), false);} }
Java8 string[] arrays, integer[], and other types of wrapper arrays into a primitive array such as int[]