Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Unable to put in one of the elements from another arraylist into another class(Resolved)

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all, I have a problem taking selected elements from 2 different arraylists placed in each class.. i am currently unable to put in one of the elements from another arraylist..
Desired output
Account Number Balance Customer Name
1001 100.0 Jack
1023 200.0 Rob
1729 300.0 Jon


The codes..





Now currently i can get the output that i wanted this way...

but the problem is that customer's arraylist is in another class and i am unable to retrive the info and put it into another different class..

Any help or comments on this topic would be great..

Thanks

Regards,
Jon
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jon,

Use packages please for classes. especially when you have related classes, it makes your life easy to manage and add classes.

How abt including a Customer reference id to a BankAccount class. So for each bank account a customer is defined and one customer can have more than one account.


When you create a account , you include the Customer id no too. when you need Customer name ( any other info)



Use map instead of List. with CustId as key , it would be easy to retrieve Customer information.


 
Jon Kho
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Balu Sadhasivam wrote:
Use map instead of List. with CustId as key , it would be easy to retrieve Customer information.



Hi Balu,
Fthank you for commenting on this topic.

can I presume that you are referring to hashmap for my problem? After reading the example on hashmap from here.
It seems that i have to create another "map" which is almost similar to arraylist..
ashMap hm = new HashMap();
hm.put("Rohit", new Double(3434.34));
hm.put("Mohit", new Double(123.22));
hm.put("Ashish", new Double(1200.34));
hm.put("Khariwal", new Double(99.34));
hm.put("Pankaj", new Double(-19.34));

Now the challenge for me is to use different elements from two existing arraylists and the coding which i have now does not seems to work(or rather do not allow me to put in the codes that i wanted).


Thanks

Regards,
Jon
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why do you need another map? a single map with Customer object as value and CustId as key would solve the problem.
 
Jon Kho
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I have managed to merge the 2 array lists together using the coding shown below under listBookings.


But I am facing a problem adding into the 3rd arraylist with new information...
Here is the coding for the BookingInfo


now currently i am able to display the 3rd array list contents.

Any help or comments on this topic would be great.
(Note: I tried using Hash maps, but there is not much information for me to learn it. Hence i am force to use this method. Thanks)

Regards,
Jon
 
Jon Kho
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all, i managed to resolved this.. it's my bad from being careless..



Thanks
    Bookmark Topic Watch Topic
  • New Topic