Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.rubaka.students_arraylist;
import java.util.ArrayList;
import java.util.List;
public class Main
{
public static void main( String[] args )
{
List<Student> students = new ArrayList<>();
Student student1 = new Student();
student1.setFirstName( "Ivanov" );
student1.setLastName( "123" );
students.add( student1 );
students.add( new Student("Petrov", "{Petr") );
students.add( new Student("Petrov2", "{Petr2") );
students.add( new Student("Petrov3", "{Petr3") );
students.add( new Student("Petrov4", "{Petr4") );
students.add( new Student("Petrov5", "{Petr5") );
for(int i = 0; i < students.size(); i++){
System.out.println( students.get( i ).getFirstName() + " " + students.get( i ).getLastName() );
}
for(Student student : students)
System.out.println(student.getFirstName() + " " + student.getLastName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.