Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to re-size an array with keeping the previous value in java?

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Thanked 0 Times in 0 Posts

    Arrow How to re-size an array with keeping the previous value in java?

    Suppose i have a book class and bookArray class.in book class contains four fields name,id ,publisher and author.
    in bookArray class:
    book bookArray=new book[20];
    i have to save those four fields in the array but after completed the array i should have re-size the array with contains the previous data. How??
    I have pass those values from the main class..

  2. #2
    Junior Member
    Join Date
    Nov 2011
    Aarhus, Denmark
    Thanked 1 Time in 1 Post


    You cannot resize arrays in java. If you really need to go with arrays you need to create a new array of the desired size and copy your data over. Instead I would use a list, try and lookup ArrayList in the javadoc, should be exactly what you want.


Similar Threads

  1. Replies: 0
    Last Post: October 25th, 2013, 03:28 PM
  2. Java 1.4 Array issues - controlling array size for dynamic usage
    By doonan79 in forum Collections and Generics
    Replies: 5
    Last Post: June 18th, 2013, 11:53 AM
  3. keeping the size of the buttons the same
    By aakaa in forum AWT / Java Swing
    Replies: 1
    Last Post: August 4th, 2012, 06:59 PM
  4. [SOLVED] Help with keeping the gui one size
    By derekxec in forum AWT / Java Swing
    Replies: 3
    Last Post: July 27th, 2011, 02:43 PM
  5. keeping track of array taht holds object
    By jack_nutt in forum Java Theory & Questions
    Replies: 1
    Last Post: June 20th, 2011, 11:17 PM