• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

copyValueOf vs ValueOf

 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,
Can someone explain me the main difference between String.copyValueOf et String.valueOf?
I've tried simply this:

and output is :
abcd
abcd
in both case...
Thanks in advance,
Cyril.
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(1) Here is the SDK 1.4.1 source code. As you can see, there is no difference.

(2)
There are 2 overloaded forms of String.copyValueOf.
public static String copyValueOf(char data[])
public static String copyValueOf(char data[], int offset, int count)
There are 9 overloaded forms of String.valueOf.
public static String valueOf(char data[])
public static String valueOf(char data[], int offset, int count)
public static String valueOf(boolean b)
public static String valueOf(char c)
public static String valueOf(int i)
public static String valueOf(long l)
public static String valueOf(float f)
public static String valueOf(double d)
public static String valueOf(Object obj)
(3)
Notice that there are three ways to create a String from an array of char: the String contructor, valueOf and copyValueOf
public String(char value[])
public String(char value[], int offset, int count)
(4)
And finally, don�t confuse String.valueOf with the primitive type wrapper valueOf methods.
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marlene for your very clear answer.
We are very lucky to learn from you...
Cyril.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use to wonder the same thing myself. So finally I decided I had better dig into the source code, so that I would stop wasting time wondering.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Marlene.
You explained this question so clearly.Except that, you taught me one method of learning
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Cyril and Calvin.
Calvin, I am not sure I understand what you mean : Except that, you taught me one method of learning. I am curious to know.
 
Calvin Yan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marlene I mean I will also read the source codes if I meet with the problems like that.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, now I understand. Thank you.
Yes, reading the source code does help sometimes. It can be very helpful when people are arguing about something, but just guessing. Then you look at the source code and settle the question once and for all.
[ July 19, 2003: Message edited by: Marlene Miller ]
 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anybody know if the source codes are publish somewhere in the Sun's web site? Downloading the SDK is too big for my machine.
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alton
In the folder where you have installed java. Look for a file src.zip.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic