Avatar of Zolf
Zolf
Flag 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
JavaJava EEJSP

Avatar of undefined
Last Comment
Zolf

8/22/2022 - Mon
ksivananth

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*" ));
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
ksivananth

listModel.get(info.position - 1).get( "Qty" ) ; //will give only quantity
listModel.get(info.position - 1).set( "Qty", 50 ) ; //will update qty to 50
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
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
ksivananth

>>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.
ksivananth

and could be a Number type too!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
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
ksivananth

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Zolf

ASKER
thanks