Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  

Cannot assign an ArrayList to an empty ArrayList



Share on Google+Share on Google+

Sarbu Diana
Cannot assign an ArrayList to an empty ArrayList
1 Answer(s)      5 years and a month ago
Posted in : Java Beginners

I have a java file, in which a method returns an ArrayList. This ArrayList is supposed to contain all the Student object which are in X year. public ArrayList<Student> studByYear(int value){

ArrayList<Student> students = StudentsManager.getInstance().getStudent√Ę‚?¨¬¶
Iterator<Student> itr = students.iterator();

ArrayList<Student> found_stud = new ArrayList<Student>(); 

while (itr.hasNext()) {
Student element =;

if(element.getYear() == value){
return null;
return found_stud;


I want to do something like this:

ArrayList<Student>found_list = new ArrayList<Student>();

if(year > 0){ if year typed in the html form is > 0

//found_list = StudentsManager.getInstance().studByYear√Ę‚?¨¬¶


getInstance() is a singleton of StudentsManager. I access StudentsManager's methods statically.

studByYear(year); returns an ArrayList of all the students that are in the year "year".

I already tried with:

 a) List<Integer> newList = new ArrayList<Integer>(oldList); here it could not compile
    b) Collections.copy(arrayList2,arrayList1); here I got exception :|
View Answers

June 30, 2012 at 1:59 AM

I mean I want to save in the ArrayList, called foundlist, the result I receive from calling the method StudentsManager.getInstance().studByYear(year); This method returns an ArrayList of students that are in a particular year. I will put foundlist in a table in html.


Related Tutorials/Questions & Answers:
Cannot assign an ArrayList to an empty ArrayList
Cannot assign an ArrayList to an empty ArrayList  I have a java file, in which a method returns an ArrayList. This ArrayList is supposed to contain... StudentsManager's methods statically. studByYear(year); returns an ArrayList of all
cannot display an arrayList in JSP
cannot display an arrayList in JSP  Hello, My bean is called Zone, i...=""; int count=0; List viewList = new ArrayList(); Iterator viewItr; Iterator itr..."; } viewList = (ArrayList); int id = Integer.parseInt(viewList.get(0
arraylist   Using arraylist class , what type of exception are throws, how can write a java programe   An ArrayList can throw... ArraylistException { void buildAlphabet() { ArrayList list = new ArrayList
ArrayList  import java.util.*; class ArrayListDemo2 { public static void main(String args[]) { ArrayList al=new ArrayList(); al.add("one"); al.add("two"); al.add("three"); al.add("four"); for(int i=0;i Expected
arraylist  Hi How can we eliminet duplicate element from arraylist? How can we find highest salary from arraylist ? How can we highest key value pair from map? Thanks Kalins Naik   Remove duplicates from Arraylist
arraylist  Hi how can we eliminet duplicate element from arraylist in java? how can we achieve data abstrcation and encapulation in java? how many type of modifier are there in java? Thanks kalins anik   Remove
arraylist  Hi i have class A , i have added employee name and id in arraylist, then how can i find out all infomation of class A using emplyee... data into an arraylist and display the data of the particular employee according
% *(noOfYearService/2). Store each employee information in different arrayList depending on his
arraylist of an arraylist
arraylist of an arraylist  Can anyone suggest me how to use arraylist of an arraylist?? how to put data into it and get data from it???? becoz i want to make rows and column dynamic which can grow as per requirement?????/ plz
arraylist and vector
arraylist and vector  what is the diff b/w arraylist and vector
Java ArrayList
Java ArrayList   How to declare unique ArrayList
ArrayList and Vector
ArrayList and Vector  hello, Why ArrayList is faster than Vector?   hii, ArrayList is faster than Vector, because ArrayList is not synchronized. Synchronization will reduce the performance of Vector
arraylist in java
arraylist in java  arraylist in java   Array List Example in java
Arraylist in java
( ) : This will create a empty ArrayList. ArrayList(Collection c ) : containing...ArrayList is a class that extends AbstractList and implements List Interface... of array how many element it will hold, they cannot grow or shrink
ArrayList object
ArrayList object  i have am ArrayList object it containg data base records in it, now i want to display this ArrayList object data in my jsp programe, plz help me
ArrayList elements
ArrayList elements  how to print ArrayList elements in reverse order... ArrayListReverse { public static void main(String[] args) { ArrayList list=new ArrayList(); list.add("Innova"); list.add("Alto
Java arraylist of arraylist
Java arrayList can make the use of other arrayList.  In one arrayList other arrayList can be added as the object† It works as two dimension array. Example of Java Arraylist of Arraylist import
comparing arraylist of an multi dimensional arraylist
comparing arraylist of an multi dimensional arraylist  can anyone help me in solving the following issue: actually i have an arraylist called dany... have to compare each arraylist with each other. like i have to take 1st arraylist
accessor arrayList
accessor arrayList  how to use an acccessor to return an arraylist?   public List getProductList(String itemName) { List list=new ArrayList(); //Add your item in the list return list; } You may wish to browse
ArrayList in java
ArrayList in java  sir i have a class contains id,name,marks of students and a parameteraised i created an arraylist... to access marks from arraylist
ArrayList programe
ArrayList programe  How to write a java program to accept an array list of Employee objects. search,delete and modify a particular Employee based on Id Number (like ID,Name&Address
vector and arraylist
vector and arraylist    suppose i have class A { public static arrylist a1(){} class B{ public static vector b1() {} } my question is how to class B method in Class A and how to get vector object values in class A without
arraylist problems?
arraylist problems?   myprogram needs to ask the user for a file name. The file will contain a name on each line. Put each of the names into an ArrayList. After you have put all of the names into the ArrayList search through
java arraylist
need to create arraylist whose name is same as type value(e.g : list1,list2... which is having type list1 in the arraylist named list1. the problem here... help how to handle this through java arraylist. xml : <?xml version='1.0
Java arraylist, linkedlist
Java arraylist, linkedlist  What is the major difference between LinkedList and ArrayList
arrayList - Java Beginners
must check through the desktop arraylist and notebook arraylist. How can I combine this two arraylist checking for throw out the msg of "Computer list is empty!" Currently I only can check for desktop arraylist empty if no desktop is added
Remove multiple elements in arraylist
Remove multiple elements in arraylist   how can we remove multiple values in arrayList? only remove method we used for single remove.but i want to delete multiple value in arrayList
ArrayList as an argument to another class
ArrayList as an argument to another class  how do you pass arraylists as arguments to another class, and how does the method/class accept this arraylist for use