Below is a Java program to find the maximum value from a list of integers:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MaxValueFromList {
public static void main(String[] args) {
// Create a list of integers
List<Integer> numbers = new ArrayList<>(Arrays.asList(10, 5, 20, 15, 30));
// Find the maximum value
int maxValue = findMaxValue(numbers);
// Print the maximum value
System.out.println("Maximum value in the list: " + maxValue);
}
public static int findMaxValue(List<Integer> list) {
// Check if the list is empty
if (list == null || list.isEmpty()) {
throw new IllegalArgumentException("List cannot be null or empty");
}
// Initialize max with the first element
int max = list.get(0);
// Iterate through the list to find the maximum value
for (int i = 1; i < list.size(); i++) {
if (list.get(i) > max) {
max = list.get(i);
}
}
return max;
}
}
This program defines a method `findMaxValue()` that takes a list of integers as input and returns the maximum value in the list. The `main()` method creates a list of integers, calls `findMaxValue()` to find the maximum value, and then prints it to the console.