Results 1 to 13 of 13
Thread: Table Data Type
- 03-14-2011, 01:31 AM #1
-
What is a "Table ADT"? What specifically are your requirements?
Edit: For what it's worth, normally, I'd store this frequency data in a HashMap<Character, Integer>.Last edited by Fubarable; 03-14-2011 at 02:14 AM.
- 03-14-2011, 02:17 AM #3
not an ADT, sorry. The characters and their counts will be kept in a table data structure.
- 03-14-2011, 02:19 AM #4
so the characters would be the 'keys' of the map?
-
- 03-14-2011, 02:25 AM #6
Ok, so if I do a myHashMap.put(A,1) for the first time I find an A, how would I update the value portion (the 1) the next time I find an A?
-
First you'd call get on the HashMap using your char as a key. If it returns null, then you know that this is the first time that this char was encountered and you'd put in a 1 for this char. Otherwise if it returns a viable Integer, you get the intValue, add one to it, and put the resulting incremented value.
- 03-14-2011, 02:31 AM #8
hmm.. looks like get is returning an object. Is it as simple as casting it to an int?
- 03-14-2011, 02:36 AM #9
nevermind, I see what what you are saying
-
No, try it and you'll see what happens if you try to cast a reference type to a primitive. You should be using a generic HashMap<Character, Integer>. So get will return an Integer. You get an int from this by calling intValue on the Integer returned, or you could just use it as is via auto-unboxing.
- 03-14-2011, 02:56 AM #11
so it would be like:
HashMap table = new HashMap<Character,Integer>;
-
- 03-14-2011, 03:28 AM #13
Similar Threads
-
Matrix Data Type
By fraB3422 in forum New To JavaReplies: 7Last Post: 02-27-2011, 02:08 AM -
Understanding limitations of int data-type
By JONCOM in forum New To JavaReplies: 11Last Post: 01-30-2011, 09:57 PM -
How to index a table with an ID with the type String
By crishantha in forum LuceneReplies: 0Last Post: 12-03-2010, 06:07 AM -
how to set NVarchar data type
By edi.gotieb in forum JDBCReplies: 9Last Post: 05-19-2010, 01:13 PM -
sychronized data type
By java girl in forum Threads and SynchronizationReplies: 3Last Post: 02-13-2009, 08:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks