How to get Individual values from twin column select

Hello Vaadin experts,

I have a doubt in twin column select.

final TwinColSelect crops = new TwinColSelect();
CropContainer cropContainer = CropContainer.createWithTestData();
for (Crops crop : cropContainer.getItemIds()) {
crops.addItem(crop.getCrop());
}

		crops.setRows(10);
		
		crops.setNullSelectionAllowed(true);
		crops.setMultiSelect(true);
		crops.setImmediate(true);
		
		crops.setLeftColumnCaption("Available Crop's");
		crops.setRightColumnCaption("Selected Crop's");
		crops.setWidth("350px");

By using crops.getValue() I am getting all te values from the right column. My problem is to iterate through the values of the right column and get the individual values.

I tried hash set ,list and iterate throught it but I am getting the following error


Caused by: java.lang.ClassCastException: java.util.Collections$UnmodifiableSet cannot be cast to java.util.HashSet
at com.zoraly.agridoc.masterregistrations.FarmerInfo$8.buttonClick(FarmerInfo.java:4368)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:490)
… 22 more

Please Help me

Thanks and Regards,
Siva.

TwinColSelect returns a UnmodifiableSet so you cannot just cast it to a HashSet. Instead, cast it to a java.util.Set.

Hi,
Thanks for your reply.

I tried

java.util.Set cropDetailsList = new HashSet ();
cropDetailsList=(java.util.Set) crops.getValue();

But I am not getting values into the set.

Are you sure you have selected (moved items from the left to the right) in the TwinColSelect?

If you do not absolutely need a HashSet then you could just use:
java.util.Set cropDetailsList = (java.util.Set) crops.getValue();

Hey Thanks. That worked fine.