How to print an arraylist in java?



How to print an arraylist in java?..

Answer / Mayur Gupta

To print an ArrayList in Java, you can use the for-each loop or the traditional for loop. Here's an example using the for-each loop:

```java
import java.util.*;

public class Main {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("Apple");
list.add("Banana");
list.add("Orange");

for (String fruit : list) {
System.out.println(fruit);
}
}
}
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Define an enumeration?

1 Answers  


What is the concept of multithreading?

1 Answers  


What is valid keyword in java?

1 Answers  


What is early binding and late binding in java?

1 Answers  


What is final, finally, finalize?

1 Answers  


What is the purpose of skeleton and stub?

1 Answers  


How do you add an element to a set in java?

1 Answers  


List some important features of java 10 release?

1 Answers  


Describe 2 different ways to concatenate two strings.

1 Answers   TCS,


What is entry in java?

1 Answers  


Explain the reason behind ending a program with a system.exit(0)?

1 Answers  


If we don’t want some of the fields not to serialize how to do that?

1 Answers  


Categories