Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - How to do Arrays.asList on only part of an Object[] array?

 
Thread Tools Search this Thread
Old 11-05-2009, 02:24 PM   #11
Default Re: How to do Arrays.asList on only part of an Object[] array?


Christian wrote:
> Lew schrieb:
>> So why are you using an obsolete version of Java?
>>

>
> there are people that need their software to work with Mac Os X ...
> sadly due to Apple's reluctance in not supporting their older
> OS/Architectures we will all be stuck with Java 5 if we want to be
> compatible to MacOsX ...
>
>
> so Java 5 even if in EoL will not be obsolete in the next years...


The OP made no mention of Mac. I don't routinely expand headers, so the
question was a natural one.

I thought I'd read that Mac had Java 6 by now.

As for not being obsolete, Java 5 is no longer available for free from Sun.

--
Lew


Lew
  Reply With Quote
Old 11-06-2009, 03:22 AM   #12
Arne Vajhøj
 
Posts: n/a
Default Re: How to do Arrays.asList on only part of an Object[] array?
Lew wrote:
> laredotornado wrote:
>> I'm using Java 1.5.

>
> You have a plethora of answers already, but I'm wondering why you're
> using an obsolete version of Java.


> So why are you using an obsolete version of Java?


How do you know that he is using an obsolete version of Java?

SUN's free version EOL'ed October 30.

But SUN's business version will first EOL June 2019.

I don't even think IBM has announced a EOL date for
WAS 6.1 with Java 1.5 yet.

I will expect Oracle to support whatever WebLogic
versions using Java 1.5 for quite some time.

Arne


Arne Vajhøj
  Reply With Quote
Old 11-06-2009, 09:06 PM   #13
laredotornado
 
Posts: n/a
Default Re: How to do Arrays.asList on only part of an Object[] array?
On Nov 4, 4:25*pm, Tom Anderson <t...@urchin.earth.li> wrote:
> On Wed, 4 Nov 2009, laredotornado wrote:
> > As you may know, the Arrays.asList method will return an ArrayList
> > object from an Object[] array. *What is the easiest way to achieve this
> > when you only want a specific range of that Object[] array, say, its
> > first element up until it's length - 1 element?

>
> Arrays.asList(anArray).subList(startIndex, endIndex);
>
> Both the array list and the sub-list are lightweight wrappers, so there's
> no copying, just two method calls and some arithmetic on each access.
>
> tom
>
> --
> That must be one of the best things you can possibly do with a piglet,
> booze and a cannon. -- D


Forgot to update this thread, but since there was consensus on Tom's
solution I tried it out and it worked great. 5 stars, - Dave


laredotornado
  Reply With Quote
Old 11-09-2009, 03:23 AM   #14
Arne Vajhøj
 
Posts: n/a
Default Re: How to do Arrays.asList on only part of an Object[] array?
Lew wrote:
> Christian wrote:
>> Lew schrieb:
>>> So why are you using an obsolete version of Java?

>>
>> there are people that need their software to work with Mac Os X ...
>> sadly due to Apple's reluctance in not supporting their older
>> OS/Architectures we will all be stuck with Java 5 if we want to be
>> compatible to MacOsX ...
>>
>> so Java 5 even if in EoL will not be obsolete in the next years...

>
> The OP made no mention of Mac. I don't routinely expand headers, so the
> question was a natural one.
>
> I thought I'd read that Mac had Java 6 by now.


It has. But only newer versions. For whatever reason Apples does
not backport.

> As for not being obsolete, Java 5 is no longer available for free from Sun.


Support is not available.

It is still available for download.

Arne


Arne Vajhøj
  Reply With Quote
Old 11-09-2009, 03:27 AM   #15
Arne Vajhřj
 
Posts: n/a
Default Re: How to do Arrays.asList on only part of an Object[] array?
laredotornado wrote:
> On Nov 4, 4:25 pm, Tom Anderson <t...@urchin.earth.li> wrote:
>> On Wed, 4 Nov 2009, laredotornado wrote:
>>> As you may know, the Arrays.asList method will return an ArrayList
>>> object from an Object[] array. What is the easiest way to achieve this
>>> when you only want a specific range of that Object[] array, say, its
>>> first element up until it's length - 1 element?

>> Arrays.asList(anArray).subList(startIndex, endIndex);
>>
>> Both the array list and the sub-list are lightweight wrappers, so there's
>> no copying, just two method calls and some arithmetic on each access.

>
> Forgot to update this thread, but since there was consensus on Tom's
> solution I tried it out and it worked great. 5 stars, - Dave


Just note that as Tom wrote then asList and subList does not copy
data.

Besides meaning good performance it also means that modifications
to the list also affects the array.

import java.util.Arrays;
import java.util.List;

public class Backing {
public static void main(String[] args) {
String[] sa = { "A", "BB", "CCC", "DDDD" };
List<String> sl = Arrays.asList(sa).subList(1, 3);
sl.set(0, "BBX");
sl.set(1, "CCCX");
for(String s : sa) {
System.out.println(s);
}
}
}

outputs:

A
BBX
CCCX
DDDD

That is fine.

You just need to be aware of it.

Arne


Arne Vajhřj
  Reply With Quote
Old 11-09-2009, 04:35 AM   #16
Lew
 
Posts: n/a
Default Re: How to do Arrays.asList on only part of an Object[] array?
Lew wrote:
>> As for not being obsolete, Java 5 is no longer available
>> for free from Sun.


Arne Vajhøj wrote:
> Support is not available.
>
> It is still available for download.


Do you have a link for a free download of Java 5 from Sun?

--
Lew


Lew
  Reply With Quote
Old 11-09-2009, 04:41 AM   #17
Lew
 
Posts: n/a
Default Re: How to do Arrays.asList on only part of an Object[] array?
Lew wrote:
>>> As for not being obsolete, Java 5 is no longer available for free
>>> from Sun.


Arne Vajhøj wrote:
>> Support is not available.
>>
>> It is still available for download.


Lew wrote:
> Do you have a link for a free download of Java 5 from Sun?


I finally found it:
<http://java.sun.com/javase/downloads/index_jdk5.jsp>

--
Lew


Lew
  Reply With Quote
Old 11-09-2009, 04:45 AM   #18
Lew
 
Posts: n/a
Default Re: How to do Arrays.asList on only part of an Object[] array?
Lew wrote:
>>>> As for not being obsolete, Java 5 is no longer available for free
>>>> from Sun.


Arne Vajhøj wrote:
>>> Support is not available.
>>>
>>> It is still available for download.


Lew wrote:
>> Do you have a link for a free download of Java 5 from Sun?

>
> I finally found it:
> <http://java.sun.com/javase/downloads/index_jdk5.jsp>


And support is available for a fee.
<http://www.sun.com/software/javaforbusiness/support.jsp>
<http://www.sun.com/software/javaforbusiness/getit_download.jsp>

So Sun's definition of "End of Service Life" is a bit loose.

--
Lew


Lew
  Reply With Quote
Old 11-09-2009, 11:35 PM   #19
Arne Vajhøj
 
Posts: n/a
Default Re: How to do Arrays.asList on only part of an Object[] array?
Lew wrote:
> Lew wrote:
>>>>> As for not being obsolete, Java 5 is no longer available for free
>>>>> from Sun.

>
> Arne Vajhøj wrote:
>>>> Support is not available.
>>>>
>>>> It is still available for download.

>
> Lew wrote:
>>> Do you have a link for a free download of Java 5 from Sun?

>>
>> I finally found it:
>> <http://java.sun.com/javase/downloads/index_jdk5.jsp>

>
> And support is available for a fee.
> <http://www.sun.com/software/javaforbusiness/support.jsp>
> <http://www.sun.com/software/javaforbusiness/getit_download.jsp>
>
> So Sun's definition of "End of Service Life" is a bit loose.


Not really.

They have a free version that they EOL relative early and
a for money version they support a lot longer.

It makes sense to me.

Arne


Arne Vajhøj
  Reply With Quote
Old 11-09-2009, 11:36 PM   #20
Arne Vajhøj
 
Posts: n/a
Default Re: How to do Arrays.asList on only part of an Object[] array?
Lew wrote:
> Lew wrote:
>>>> As for not being obsolete, Java 5 is no longer available for free
>>>> from Sun.

>
> Arne Vajhøj wrote:
>>> Support is not available.
>>>
>>> It is still available for download.

>
> Lew wrote:
>> Do you have a link for a free download of Java 5 from Sun?

>
> I finally found it:
> <http://java.sun.com/javase/downloads/index_jdk5.jsp>


You can still download Java 1.1.8 if you want to.

http://java.sun.com/products/archive/

Arne



Arne Vajhøj
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
No array is defined ... John Dean Computer Support 2 03-16-2006 08:02 PM
Re: Stop posting politics at alt.culture.alaska Aratzio Computer Support 102 11-18-2004 01:26 AM
Everytime I try to open OE or IE I get windows installer trying to install office 2003 cteq1@athotmail.com Computer Support 14 11-12-2004 09:00 AM
Applying an image to a new raid array. Michael-NC Computer Information 1 07-21-2004 05:09 AM
Ultra ATA 100/133 Controller configuration? Flippor Computer Support 3 04-02-2004 05:59 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46