← All Exercises

Java Thread Basics

intermediatejava~25min

Background

Java threads enable concurrent execution, with Runnable for task definition and join for synchronization.

Problem

Write a Java method that launches multiple threads to compute squares concurrently and collects results using join.

Input

An array of integers to square concurrently.

Output

An array of squared values in the same order.

Sample tests

Sample 1

Input: [1, 2, 3, 4]
Expected: [1, 4, 9, 16]

Your solution

Learning objective

Learn thread creation with Runnable lambdas, start/join synchronization, and concurrent array writing.