Exforsys

Online Training

Array Handling

This is a discussion on Array Handling within the Java forums, part of the Programming Talk category; I have an array defined in Java as below: Test[] a = new Test[100]; The array is full. I want ...


Go Back   Exforsys > Programming Talk > Java

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-02-2007, 04:34 PM
Senior Member
 
Join Date: Apr 2006
Posts: 145
Rahulbatra is on a distinguished road
Array Handling

I have an array defined in Java as below:

Test[] a = new Test[100];

The array is full. I want to grow this array. But I want to achieve the growing of array such that array grow is done for any type, not just arrays of objects.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-08-2007, 04:38 PM
Senior Member
 
Join Date: Apr 2006
Posts: 153
cyrus is on a distinguished road
Test[] a = new Test[100];

You can grow the array Test as below

int arraynewl = a.length * 15 / 12 + 12;
The above statement computes the length of the new array to be defined that is length of the new grow array.

Now assign the new length to the array and define it newly as
Test[] arrayn = new Test[arraynewl];
System.arraycopy(a, 0, arrayn, 0, a.length);
a = arrayn;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-08-2007, 05:43 PM
Senior Member
 
Join Date: Apr 2006
Posts: 145
Rahulbatra is on a distinguished road
Thanks it was a very good suggestion. I tried this and also got the result. But if we make the above generic that is the growing of array such that array growth is done for any type, not just arrays of objects. Can you provide idea to achieve this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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 On


Similar Threads

Thread Thread Starter Forum Replies Last Post
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 06-15-2004 07:00 AM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 06-01-2004 07:01 AM
comp.lang.c FAQ list Table of Contents Steve Summit Tech FAQ 0 06-01-2004 07:00 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit Tech FAQ 0 06-01-2004 07:00 AM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 05-15-2004 07:00 AM


All times are GMT -4. The time now is 06:24 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.