Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Collection Examplw

Posted on 2004-10-27
7
Medium Priority
?
195 Views
Last Modified: 2010-03-31
Hi,

Would like an example of a collection class

Cheers
0
Comment
Question by:Cyart
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 12425003
Here's one that (just for instance ;-)) models a Bank having a collection of Customer

import java.util.*;

public class Bank {
      private Map customers;
      // need other attributes pertaining to the bank itself
      
      public Bank() {
            customers = new HashMap();
      }
      
      public void addCustomer(Customer c) {
            customers.put(c.getId(), c);
      }
      
      public Customer getCustomer(Integer id) {
            return (Customer)customers.get(id);
      }
      
      // need a remove, getCustomers too
      
      public String toString() {
            return customers.toString();
      }

}
0
 

Author Comment

by:Cyart
ID: 12425069
Have you got a basic main to test this with,just so I can see it working
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12425175
Well, first you need to create a Customer class then that's fairly trivial. Do that first. Clue: the relationship between Bank/Customer is the same as Customer/Account
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 8

Assisted Solution

by:kiranhk
kiranhk earned 400 total points
ID: 12425654
check out the collections examples
http://javaalmanac.com/egs/java.util/pkg.html
0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 12428040
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12498244
did you find any of the suggestions useful?? havent heard from you for a long time
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12542780
8-)
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question