How to transfer class data from a Array to a ArrayList

This question already has an answer here:

  • Create ArrayList from array 32 answers

  • However I have the following error on the 2 lines before cc = cc + 1. "cards cannot be resolved to a variable"

    That means that you haven't declared cards in a way / place that allows draw() to see the declaration.

    You say:

    In the main method the Array cards contains 52 card objects each with their own data.

    It sounds like you have declared cards as a local variable within the main method. Local variables are only in scope for statements in the current method body.

    The cards array either needs to be declared as a field of the enclosing class, or it needs to be passed as a parameter to draw . I can't say which would be better without seeing your complete code.

    链接地址: http://www.djcxy.com/p/17638.html

    上一篇: 我将如何从一个数组切换到一个数组列表?

    下一篇: 如何将类数据从数组传递到ArrayList