Adding element to array


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Adding element to array

  1. #1
    Join Date
    Oct 2004
    Posts
    21

    Adding element to array

    Hi,
    I was wondering how to insert elements into an array, so if i have an array thats like
    int[] intBlah = int[0];
    Can I add an element to this array? Ive seen a bunch of different ways to do it but I cannot figure out how.

  2. #2
    Join Date
    Sep 2004
    Posts
    223
    do you mean to extend the size of the array beyond what it is set to?
    A kram a day keeps the doctor......guessing

  3. #3
    Join Date
    Oct 2004
    Posts
    21
    yes well, I have a string of variable length, I break it up into a char array so each one is a seperate value in the array. Oh wait I can just use length and i dont need to add make the array any bigger. But is it possible to make the array bigger?

  4. #4
    Join Date
    Sep 2004
    Posts
    223
    i dont think that it is, thats what i was going to say
    A kram a day keeps the doctor......guessing

  5. #5
    Join Date
    Oct 2004
    Posts
    311
    No, an Array has a static size in Java. If you want to do something with a dynamic array size you need to do it via a different class: java.util.ArrayList.

    This class has an add(Object); method, which allows you to add an object to the end of the ArrayList.
    after you have added all your elements to the list, you can convert it into an array using the toArray() method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center