aspose file tools
The moose likes Java in General and the fly likes java Map- code issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "java Map- code issue" Watch "java Map- code issue" New topic
Author

java Map- code issue

yam vek
Greenhorn

Joined: Mar 30, 2010
Posts: 1
Map code issue:

Have Map accepting values from 2 tables (txn, txn_pending)

map accepts key as txnid and value as TransactionDataModel as below,

Map<Long, Transaction> transactions = new HashMap<Long, Transaction>()
transactions.put(tpAccountTxnId, transaction);

Flow 1: queries value from table(txn) and has 3 record which occupies position : 1,11,12 in map
records keys:
tpAccountTxnId : 21804
tpAccountTxnId : 22723
tpAccountTxnId : 23604

Flow 2: TxnId which is key has null value(designed as per req) for table 2(Txn_pending) and hence have replced null values with increment values of int i=1;
records keys:
tpAccountTxnId : null
tpAccountTxnId : null

issue: when i try to replace null values with increment value of int i=1, it replaces record key 21804 which is placed in position 1 of "txn" table.

can anyone please suggest some solution to accept both txnid with null and not null values in same map without losing any record or replacing existing record.
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
HashMap will allow only one null as a key. I didnt get your question, sorry
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

yam vek wrote:... and has 3 record which occupies position : 1,11,12 in map ...

issue: when i try to replace null values with increment value of int i=1, it replaces record key 21804 which is placed in position 1 of "txn" table.

There's one thing I don't understand here: what do you mean with the 'position' in a map?

A Map is an unordered collection. Entries (key-value pairs) in a map do not have a position.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: java Map- code issue
 
Similar Threads
pls validate my locking strategy - all inputs are g8ly appreciated. (URLyBird)
Indexed Collections
maximum open cursors exceeded
What would be the best datastructure to hold huge data
Hashtable