Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: how to extend a byte[] array with a null byte?

Reply
Thread Tools

Re: how to extend a byte[] array with a null byte?

 
 
Tom McGlynn
Guest
Posts: n/a
 
      04-17-2008
On Apr 17, 2:09 pm, "Peter Duniho" <(E-Mail Removed)>
wrote:
....
> I was surprised to not be able to find a helper method in the Array or
> Arrays class that would do the copy. It's possible one exists elsewhere
> and I just haven't run across it yet. That would be nicer (and possibly
> perform better) than the for() loop above.
>


You're probably looking for the System.arraycopy method.

In this case...
System.arraycopy(rgbString, 0, rbgDatabase, 0,
rgb.String.length());


Regards,
Tom McGlynn
 
Reply With Quote
 
 
 
 
Kevin McMurtrie
Guest
Posts: n/a
 
      04-18-2008
In article <(E-Mail Removed)>,
"Peter Duniho" <(E-Mail Removed)> wrote:

> On Thu, 17 Apr 2008 20:57:33 -0700, Lew <(E-Mail Removed)> wrote:
>
> > [...]
> > You use System.arraycopy(), as others have suggested, when you're using
> > a target array that you need to allocate outside the call.

>
> I understand that. But part of a well-designed API is discoverability. A
> natural place to look for that functionality is in the classes involved,
> as opposed to a general purpose utility class (especially considering that
> that utility class consists mostly of things related to the run-time
> environment, rather than management of data within a Java program).
>
> The arraycopy() method, to me, seems like an anomaly in the System class,
> whereas it would seem quite at home as a static method in either the Array
> or Arrays class.
>
> YMMV.
>
> Pete


The System and Runtime classes are an odd collection of things that
needed a home in the Java 1.0 days. That was back when Java was supposed
to be a compact, super efficient language for browsers and embedded
devices. (Yes, the flaws in that logic were visible back then too.)

--
Block Google's spam and enjoy Usenet again.
Reply with Google and I won't hear from you.
 
Reply With Quote
 
 
 
 
Andreas Leitgeb
Guest
Posts: n/a
 
      04-18-2008
Lew <(E-Mail Removed)> wrote:
> Besides, Arrays.copyOf() is far more idiomatic and something I'd almost
> certainly use 99.9% of the time in preference to System.arraycopy() (which
> doesn't even follow Sun's own naming conventions).


The only usecase (that I can think of right now), where copyOf doesn't
do better than arraycopy, is when you want all the elements of two or more
separate arrays concatenated in one new big array. For the first array,
copyOf (to the final length) is fine, but then?
I do not claim that this was a particularly common usecase, but it seems
plausible to me that it may come up casually.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Null pointer (NULL array pointer is passed) aneuryzma C++ 3 06-16-2008 05:48 AM
Re: how to extend a byte[] array with a null byte? Tom McGlynn Java 4 04-18-2008 11:49 PM
Re: how to extend a byte[] array with a null byte? Patricia Shanahan Java 0 04-17-2008 06:47 PM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM



Advertisments