Hey everyone new to java and have been trying to get my to get array to do two things. Those are 1. Sort using the sort method and 2. Only generate random numbers between 1-100. I have looked through the Oracle site on the sort method but I do not think I understand it. Thanks in advanced.
I would prefer to use an [Int]Stream:-The Random#ints() method creates an IntStream. In this instance that IntStream processes 100L (it's a long) int numbers minimum 1 and maximum < 101. (Range contains 101 − 1 = 100 numbers.) The toArray() method simply collects all the numbers processed as an array. You can of course interject another method call, which replaces the first IntStream by a second one containing the numbers in a particular order (line 2):-Note I am using different indentation with the dot operators aligned. This is another way to do it:-...or even...If any of that last code looks familiar it is because Arrays#stream() is another way to create an IntStream. You now have the original and the sorted version.