aspose file tools
The moose likes Beginning Java and the fly likes GregorianCalendar to ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "GregorianCalendar to ArrayList" Watch "GregorianCalendar to ArrayList" New topic
Author

GregorianCalendar to ArrayList

Jacob Coddaire
Ranch Hand

Joined: Jan 11, 2011
Posts: 36

Hey guys. I've got a small bit of code i'm having trouble with. Here's the idea. The user has a JTextField to put a date into. Once they put in the date, it is
1) Checked to make sure it is actually a date
2) Converted into type gregordianCalendar
3) Stored in an ArrayList for the future part of the program

I'm having trouble converting from GregordianCalendar to Array List. Any Help?


The method transactions() looks like this:



The class Transaction looks like this


and the class TransactionType looks like this:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
Don't return the transactions List from the transactions method. Return an unmodifiable copy, with this method. That way, nobody can get their hands on the transactions list and change the transactions. And change the declared type of the List (and return type for that method) to List<Transaction>. I also think you should make all the fields in the Transaction class final, again so nobody can change them. Your Transaction class will then need a constructor. Since GregorianCalendar is mutable, you would have to return a copy of the date from any getDate() method in the Transaction class. Again, to prevent anybody changing the details of the transaction.

Why have you got a return; statement in the catch block? You wold be better putting the reading part in a loop, so it will try again until a date is entered in the correct format.

You cannot change a Calendar object to a List. What you can do it set it as the field in the new Transaction object, and add that Transaction to the List.

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: GregorianCalendar to ArrayList
 
Similar Threads
convert a string to java.sql.Date object
48 hours rule, pls recomment
Format method in SimlpleDateFormat
String conversion
Calendar 1st day of week changes?