aspose file tools*
The moose likes Beginning Java and the fly likes Set holding two dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Set holding two dates" Watch "Set holding two dates" New topic
Author

Set holding two dates

Amy Dickens
Greenhorn

Joined: Mar 25, 2008
Posts: 2
Hello

Is there a way of having a list that contains 2 date objects?
e.g.


or do i need to create a class that holds the two dates in one object?
e.g.


Thanks
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

Amy,
It depends on whether you want the Set to have one object or two.

If one object, you need the helper object in your second example. If the dates can be "lose" in the set, you can do:


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38788
    
  23
Welcome to the Ranch.

For collections etc., I suggest you have a look at the Java Tutorials about collections.

Note there are several kinds of collection, Lists Sets and Maps being the most popular. You are confusing Lists and Sets in what you posted.

Yes, you can set up a List or a Set of Dates, but the two are different: Lists can contain duplicates of the same value and Lists are ordered (the first object added is at the beginning and the last at the end).
You can set up an object to hold two Dates, too. It all depends what you want to do with them. You can have a Set:You can have a List:Or you can have an object whihc has two dates in:Read the link I qouted and see how you get on with that.
CR
Amy Dickens
Greenhorn

Joined: Mar 25, 2008
Posts: 2
Thanks guys very much for your time

I understand the difference between Set & List, and my program should not allow two objects of type SomeObject (as in the previous code) to have the same dates...

And so i guess i need to create SomeObject class

I really appreciate it
Thanks again
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38788
    
  23
Originally posted by Amy Dickens:
Thanks guys very much . . . my program should not allow two objects . . .to have the same dates
You're welcome.

If you want to make sure there are two different dates, make the date object override the equals method, then put a test in the constructor of TwoDates which throws an Exception if the two are equal. You might even want to create a SameDateException.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set holding two dates