System.out.println("Enter the number of elements needed: " );
System.out.printf("Enter value 1: ");
value.add(in.nextInt());
System.out.printf("Enter value 2: ");
value.add(in.nextInt());
System.out.printf("Enter value 3: ");
value.add(in.nextInt());
System.out.printf("Enter value 4: ");
value.add(in.nextInt());
System.out.printf("Enter value 5: ");
value.add(in.nextInt());
How do I print the size of my ArrayList before entering any values?
CodePudding user response:
you can call .size()
on any list at any time, but prior to adding any values it will return 0
CodePudding user response:
In Java ArrayList is dynamic so if you haven't added any values into it the size is 0.