Returning vector

I created the following vector(bookauthorVec) in book class and trying to return in Library class. It compiles, but nothing appears in JList(booklist). I already tested getBookAuthor() with main and it works. When I created vector(bookauthorVec) inside of Library class it worked. If I return string from Book class and store to vecBookAuthor in Library class it also worked.(It appears in JList(booklist).
Book class
public Vector getBookAuthor(){
      for(int i = 0; i < bhm.size() ; i++){
return bookauthorVec;
Library class
Vector vecBookAuthor = new Vector();
Book book = new Book();
vecBookAuthor = book.getBookAuthor() ;

JList bookList = new JList(vecBookAuthor);

Any idea?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
firstly you are better off doing:
Book book = new Book();
Vector vecBookAuthor = book.getBookAuthor() ;

If you want to add things later to the list then you should use a Vector to create it and should instead use a DefaultListModel.
Mick BarryJava DeveloperCommented:
Why don't you simply return bhm from getBookAuthor?
dkim18Author Commented:

firstly you are better off doing:
Book book = new Book();
Vector vecBookAuthor = book.getBookAuthor() ;

then how do I access Book class' public function from Library class?
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Mick BarryJava DeveloperCommented:
> Vector vecBookAuthor = new Vector();

here you create a new empty vector

> Book book = new Book();
> vecBookAuthor = book.getBookAuthor() ;

And here you assign the variable a new value.
So the vector you created in the first line is unused.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mick BarryJava DeveloperCommented:
Where do actually add the elements to bhm?
Unless you add them somehow in the constructor, then it will be empty. Which is why the list is empty.

I would think you should be passing the book details to its constructor.
Mayank SAssociate Director - Product EngineeringCommented:
Might also create a problem when you add some more elements to the bhm Vector and again call the getBookAuthor () method, because then you will end up adding all the previously added elements again. Where are you initializing the bhm and bookauthorVec Vectors, and adding data to the bhm Vector?
Mayank SAssociate Director - Product EngineeringCommented:
>> bhm.get(titleVec.elementAt(i).toString())

Oh, so there's a titleVec too. By the way, what is the data-type of bhm? Is it a Vector too (initially, it looked like). But Vector does not have a get (String) method if I'm right. It only has a get (int) method.
dkim18Author Commented:
thank you for all your help. I stored objects in vector and then put it in JList.
I already submitted this proj and working on next one.
Again, your comment help me a lot.
Mick BarryJava DeveloperCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.