Sebastian Abiel
Sebastian Abiel

Reputation: 33

How to cast an Object to Arraylist

I need cast an Object to Arraylist:

<% Arraylist<Products> mypr = sesion.getAttribute("products");  %>
            <table class="table table-condensed">
                <tr>
                    <th>Id</th>
                    <th>Category</th>
                    <th>Model</th>
                    <th>Stock</th>
                    <th>Price</th>
                </tr>
                <%
                    for (Products xx : mypr) {
                        out.println(xx.toString() + "<br>");
                    }
                %>

Upvotes: 1

Views: 4238

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201537

Assuming it's an ArrayList, you could cast it (I'd recommend the List interface like)

List<Products> mypr = (List<Products>) sesion.getAttribute("products");

Upvotes: 2

Related Questions