title: I don't understand how this line works: "System.out.println("\nCard: " + Deck.get(number).getValue() + " of " + Deck.get(number).getSuit() );"
body: <p>The code below is a code shared with me by someone who I can't reach right now. I'm still new to array listing, method chaining, and pretty much to coding as well. I tried converting the &quot;Deck.get(number).getValue()&quot; into &quot;Deck.getValue()&quot; and some other variations but the code seems to fail everytime I do so. Can someone explain that specific line and why it only works when chained?</p>
  <p>P.S.</p>
  <ul>
  <li>Apologies to everyone who finds this post too basic or tedious due to lack of clarity. This is my first time posting, and I am what my username suggests.</li>
  </ul>
  <p>import java.lang.Math;
  import java.util.*;</p>
  <p>public class Card {</p>
  <pre><code>private String suit;
  private String value;
  
  
  public static void draw(){
  
      int number = (int) (Math.random() * Deck.size());
      System.out.println(&quot;\nCard: &quot; + Deck.get(number).getValue() + &quot; of &quot; + Deck.get(number).getSuit() );
      Deck.remove(number);
  }
  
  public static void count(){
  
      System.out.println(&quot;\nCards left in the Deck: &quot; + Deck.size());
  
  }
  
  public Card(String suit, String value){
      this.suit = suit;
      this.value = value;
  }
  
  static ArrayList&lt;Card&gt; Deck = new ArrayList&lt;Card&gt;(52);
  
  public String getSuit(){
      return suit;
  }
  
  public String getValue(){
      return value;
  }
  
  public void setSuit(String suit){
      this.suit = suit;
  }
  
  public void setValue(String value){
      this.value = value;
  }
  
  
  public static void main (String[] args){
  
      String[] Suits = {&quot;Clubs&quot;, &quot;Spades&quot;, &quot;Hearts&quot;, &quot;Diamonds&quot;};
      String[] Values = {&quot;A&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;, &quot;7&quot;, &quot;8&quot;, &quot;9&quot;, &quot;10&quot;, &quot;J&quot;, &quot;Q&quot;, &quot;K&quot;};
  
      for(int i = 0; i &lt; 4; i++){
          for(int a = 0; a &lt; 13; a++){
              Card Card = new Card(Suits[i], Values[a]);
              Deck.add(Card);
          }
      }
      int choice;
      do{
          cls();
  
          System.out.println(&quot; -----------&quot;);
          System.out.println(&quot;|1. Draw    |&quot;);
          System.out.println(&quot;|2. Count   |&quot;);
          System.out.println(&quot;|3. Exit    |&quot;);
          System.out.println(&quot; -----------&quot;);
  
          System.out.println(&quot;Choose an Action: &quot;);
          Scanner sc = new Scanner(System.in);
          choice = sc.nextInt();
  
          if (choice == 1)
              {
                  draw();
              }
          else if (choice == 2)
              {
                  count();
              }
          
      }while(choice!=3);
  }
  </code></pre>
  <p>}</p>