Populating ArrayList without using add()



  • Java has a dynamic unthreadsafe array called ArrayList in which you populate it using the add(Object o) method.

    Take a look at this: [url=http://forum.java.sun.com/thread.jspa?messageID=9596523]http://forum.java.sun.com/thread.jspa?messageID=9596523[/url]

    Some supid instructor is telling them they cannot popluate it with add and have to do it another way and to make a class to do that. Is this from WTFU?



  • Maybe I misread that, but it seems like the students confused the difference between the wrapper object and the underlying data objects contained within the wrapper object's internal list.

    Besides, you can populate an ArrayList from other structures; i.e.: .

    SomeObject myArray[] = { someObject1, someObject2, someObjectN };
    myArrayList.addAll(Arrays.asList(myArray));
    


  • It appears that the student is completely misunderstanding not only the assignment, but some basic concepts in Java programming.  It could be the professor's fault, or it could simply be the student.



  • @bstorer said:

    It appears that the student is completely misunderstanding not only the assignment, but some basic concepts in Java programming.  It could be the professor's fault, or it could simply be the student.

    Hard to say for sure without seeing the complete assignment, but my money's on the professor.
     



  • My guess is that it's an intro class where the professor wants them to code up their own data structure, to ensure that they actually know how the stuff works.  If that's the case, this kid probably doesn't....


Log in to reply