Just have a problem with this, how do we rewrite the above code so that only a single String object is created?
String is immutable, isnt studentDetails already one single String object
public void displayString(Student[] students)
{
String studentDetails = "";
for (Student stu : students)
{
studentDetails += stu.getFirstName();
studentDetails += " ";
studentDetails += stu.getLastName();
studentDetails += " ";
studentDetails += stu.getAge();
studentDetails += "\n";
}
System.out.println("Student Details are: ");
System.out.println(studentDetails);
}