• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

questions

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i had few questions and doubts please clear it

1)

in k&B (p.no 428)
it told that LInkedHashmap will be used for fast iteration and hashtable for faster addition and deletion.i doubt that since the LinkedHashset is for faster addition and deletion the LinkedHashMap is for faster addition adn deletion rather than what stated in the K&B.

2)
Exact diff b'tween parseXXX(), valueOf();xxValue();

to my know

the parseXXX(); and xxxValue();
will return the primitive value for the wrapper objects passed in parseXXX(); and the for wrapper objects invoked by xxxValue();

the valueOf() will create the wrapper objects

is there any diff between parseXXX() and xxxValue()



q)
what is the precedence given in the system.out.println() stmt
[ April 25, 2005: Message edited by: Parameswaran Thangavel ]
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

is there any diff between parseXXX() and xxxValue()



Yes.
parseXXX returns a primitive
xxxValue returns a wrapper object

what is the precedence given in the system.out.println() stmt



The expression that gets passed to println() will be evaluated normally before the result is passed to the println method, so all the usual precedence rules apply. Consider this example:



The output is:
28.25hello722.0[one, two]
28.25hello722.0[one, two]

3 + 5 evaluates to 8.
d evaluates to 2.25.
8 + 2.25 evaluates to 10.25.
2 * 9 is grouped because * has higher precedence than + so JVM evaluates 2 * 9 to 18.
10.25 + 18 evaluates to 28.25.
28.25 + "hello" evaluates to "28.25hello"
"28.25hello" + 7 evaluates to "28.25hello7"
11.0 * 2 is grouped because * has higher precedence that + so JVM evaluates 11.0 * 2 to 22.0.
"28.25hello7" + 22.0 evaluates to "28.25hello722.0"
list is an object reference, so JVM knows to invoke list.toString() implicitly to evaluate list as an operand for the String concatenation operator +
list.toString() returns "[one, two]"
"28.25hello722.0" + "[one, two]" evaluates to "28.25hello722.0[one, two]"
The completed String "28.25hello722.0[one, two]" gets passed as a single argument to println()
 
Joe Sondow
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

in k&B (p.no 428)
it told that LInkedHashmap will be used for fast iteration and hashtable for faster addition and deletion.



Where does it say Hashtable is good for faster addition and deletion? On page 428 the section on LinkedHashMap says, "Although it will be somewhat slower that HashMap for adding and removing elements, you can expect faster iteration with a LinkHashMap."

i doubt that since the LinkedHashset is for faster addition and deletion the LinkedHashMap is for faster addition adn deletion rather than what stated in the K&B.



Where does it say that LinkedHashSet is for faster addition and deletion?
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi joe
i am not able to follow what k&B is telling.
i am confused with it.

can u please explain me or give me some consolidated info please.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
parseXXX returns a primitive
xxxValue returns a wrapper object


hi
parseXXX and xxxValue both returns the primitive.
please check the below syntax

double d = i2.doubleValue();
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
parse methods are parsing a string with or without radix to give you a primitive belonging to that class

xxxvalue methods are available for all primitives in the Wrapper class

just taking Integer and Long as examples here
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

If you look at the java API specifications from sun, here's what they say on the valueOf method :
____
The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method
In other words, this method returns an Integer object equal to the value of: new Integer(Integer.parseInt(s))
____
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hope this helps

1.valueOf(): is static and it providess an alternate way to create wrapper objects, it can take a string or a string and a int radix value as arg.
2.xxxValue() : convert the value wrapped by the wrapper object to a primitive value, it takes no arguments
3.parseXxx() : Takes string as argument and proivdes a primitive equivalent. It is static.
 
Joe Sondow
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joe Sanowitz:
[QB]Yes.
parseXXX returns a primitive
xxxValue returns a wrapper object
[QB]



Sorry, my bad. I was thinking of valueOf, not xxxValue.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic