File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java Map- code issue

 
yam vek
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HashMap will allow only one null as a key. I didnt get your question, sorry
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic