how can i passing the list from addCard to printHand?

public void addCard(Card c){
		ArrayList<String> list= new ArrayList<String>();
		list.add(c.toString());
		
	}
	public void printHand(){
		
		for(String i:list){
			System.out.print(i+" ");
		}
	}

Thanks

Either define ArrayList list globally or make printHand accept it as a parameter.

You can also do this... invoke printHand(list) from your addCard method.

public void addCard(Card c){

      ArrayList<String> list= new ArrayList<String>();

      list.add(c.toString());

      printHand( list );

      }

      public void printHand(ArrayList list){
  
      for(String i:list){

      System.out.print(i+" ");

      }
      }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.