List « cast « Java Data Type Q&A

1. Cast a List<> in java?

Hi is it possible to cast a List? i have an abstract class that has a method that takes some sort of List<>, iterate through it in a for loop getting each ...

2. Casting - foreach - java

I have a one method like this:

private void myMethod(List<?> myLists) {

   for (Object val : myLists) {
       val.getMyOtherMethod(); // for example

3. What happens when a ListIterator is created?

I had two classes: ParentClass and SubClass. SubClass inherit from ParentClass. I had the following code: (inside class)

List<SubClass> lstSub;

//some initialization

public ListIterator getLstIterator(int i) {
   return lstSub.listIterator(i);
And client class uses it ...

4. Method receive List of more data types as parameter

I have a method and as a parameter I send List. The method looks like this:

public static void setSanctionTypes(List<QueueSueDTO> items) {

    for (QueueSueDTO dto : items) {


5. class cast exception: java.lang.String incompatible with [Ljava.lang.Object;

What is wrong with below code ?

List<Object[]> currencies = null;
List<String> currencyList = new ArrayList<String>();

//code to fetch currency
String currencySql = "select C.Currency from Currency C";
Query currencyQuery = this.em.createQuery(currencySql);

currencies = currencyQuery.getResultList();

for (Object[] currency ...

6. cast a List to a Set

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...

7. List casting

8. Problem with casting List

10. class cast exception from List.toArray()