Я хочу напечатать элементы в моем Arraylist без использования какого-либо цикла, это возможно в Java?
import java.util.ArrayList;
class Person
{
String name;
String role;
public Person(String name, String role)
{
this.name = name;
this.role = role;
}
}
class Main
{
public static void main(String[] args)
{
Person person1 = new Person("george","programmer");
Person person2 = new Person("barack","programmer");
Person person3 = new Person("ismail","programmer");
ArrayList <Person> people = new ArrayList <Person>();
people.add(person1);
people.add(person2);
people.add(person3);
System.out.println(people.get(0));
System.out.println(people.get(1));
System.out.println(people.get(2));
}
}