CJCoding With Joseph
15free / daySign inCreate account

Thompson Rivers University

Question 4

Lab 4 Collections - SM 2025

The java.util.Arrays class has methods that operate across all elements in that collection type. You can find details at https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html.

Create a short driver program with the following features:

  1. Create an array of 20 random values in the range of 1 to 999.

  2. Use the toString() method of the Arrays class to output the contents.

  3. Use the copyof() method of the Arrays class to create a copy of this array.

  4. Use the sort() method of the Arrays class to sort the second array.

  5. Use the toString() method of the Arrays class to output the contents.

  6. Try the binarySearch() method of the Arrays class to search for a few target values in the sorted array. Try some values that are in the list and some that are not. Output the result returned from each search.


Step 1: Generate and Print the Original Array

Members only

Keep reading this lesson

You've reached the end of the free preview. Unlock the rest of this lesson plus 54 more lessons in Thompson Rivers University.

  • Unlimited coding questions
  • Unlimited access to all classroom material
  • Weekly live call for questions and guidance
  • 3,000 AI tutor tokens / month
  • Personal SQL database (3 MB)
  • Progress tracking

Cancel any time.