JListmyList = new JList<>(new String[]{"Apple", "Banana", "Orange", "Mango"}); List selectedValues = myList.getSelectedValuesList(); System.out.println(selectedValues);
Object[] selectedValues = myList.getSelectedValues(); for (Object value : selectedValues) { System.out.println(value); }This example gets the selected values from the JList as an Object array using the getSelectedValues() method. Then, it loops through each value and prints it to the console. In conclusion, the package library used in these examples is javax.swing.