Get last element in arraylist

Viewed 42345

In the below code, it calls an element exactly once. How can i make it print out "this is the last element in the arraylist" when everything has been removed, and there is only one element remaining.

ArrayList<String> Responselist = new ArrayList<String>();
Responselist.add(CommentResponse());
Responselist.add(TriviaResponse());
Responselist.add(CriticResponse());
String[] SelectRand = new String [3];

for (int i = 0; i < SelectRand.length; ++i)
{
    int rnd = (int) (Math.random() * Responselist.size());
    SelectRand[i] = Responselist.get(rnd);
    Responselist.remove(rnd);
}

for (String x : SelectRand)
{
    if (!(Responselist.isEmpty()))
    {
        System.out.println(x);
    }
}
4 Answers
Related