Link to home
Start Free TrialLog in
Avatar of Zolf
ZolfFlag for United Arab Emirates

asked on

HashMap return type

Hello there,

I have this line of code

System.out.println(" SSSS   "+listModel.get(info.position - 1));

Open in new window


which returns a Hashmap<String,String>

 SSSS   {Qty=45, Name=  Regulator , Sr.No.=1}

now I want to remove the Qty data only from this output.how can i do it.

cheers
ZOlf
Avatar of ksivananth
ksivananth
Flag of United States of America image

you mean remove from hashmap?

listModel.get(info.position - 1).remove( "Qty" ) ;

if you want to remove from just the string representation, try this

System.out.println(" SSSS   "+listModel.get(info.position - 1).replaceAll( "Qty=%d*" ));
Avatar of Zolf

ASKER

i mean get only the qty data from the Hashmap. basically i am writing a feature to update the qty when user enters a wrong qty. so i am trying to get the qty amount from the list and update it with the new value. please help
listModel.get(info.position - 1).get( "Qty" ) ; //will give only quantity
listModel.get(info.position - 1).set( "Qty", 50 ) ; //will update qty to 50
Avatar of Zolf

ASKER

it will hold the qty in a String.correct?

something like this

String qty = listModel.get(info.position - 1).get( "Qty" ) ; //will give only quantity
>>it will hold the qty in a String.correct?

depends on how the map is defined, it may hold String/Object. print the type of the value and you'll come to know but based on definition of the maps, you may have to typecast.
and could be a Number type too!
Avatar of Zolf

ASKER


print the type of the value and you'll come to know but based on definition of the maps, you may have to typecast

can you please give me an e.g.
ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zolf

ASKER

thanks