HashMap return type

zolf
zolf used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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*" ));

Author

Commented:
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
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Author

Commented:
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!

Author

Commented:

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.
System.out.println(" SSSS   "+listModel.get(info.position - 1).get( "Qty" ).getClass().getName() );

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial