Guest User

Untitled

a guest
Feb 17th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. import java.util.stream.IntStream;
  2.  
  3. class Threads {
  4.  
  5. public static void main(String... args) {
  6.  
  7. IntStream
  8. .range(0, 10)
  9. .mapToObj(i -> new Thread(() -> System.out.println(Thread.currentThread().getName())))
  10. .forEach(thread -> thread.start());
  11. }
  12. }
  13.  
  14. // Output:
  15. /*
  16. Thread-0
  17. Thread-3
  18. Thread-1
  19. Thread-2
  20. Thread-4
  21. Thread-7
  22. Thread-5
  23. Thread-6
  24. Thread-9
  25. Thread-8
  26. */
Add Comment
Please, Sign In to add comment