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.


>> REGISTER NOW TO START POSTING


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

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30

Thread: Keeping track of found objects in array and smallest value

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Keeping track of found objects in array and smallest value

    I suggested that you create a NEW array of the desired size.
    Then copy the elements from the old array to the new array. The Arrays class has a method to do that.

    ArrayList is a java class. See the API doc for how to create one and what methods it has.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    Jan 2014
    Posts
    30
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default Re: Keeping track of found objects in array and smallest value

    I have set my original 2 arrays to 10, so now if I make a third array to copy my 2nd array to, then there will be some slots that will be filled with 0's and those will get copied over. I guess I should of done your array list way in the beginning but I dont think I am allowed use arraylist for this.

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Keeping track of found objects in array and smallest value

    If you have an array with 10 slots with the first 6 elements containing data
    and create a new array with 6 slots
    and copy the first 6 slots from the first array to the second array, (See the Arrays class for a method)

    there will NOT be any empty slots with 0s in the new array.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member
    Join Date
    Jan 2014
    Posts
    30
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default Re: Keeping track of found objects in array and smallest value

    Im aware of that but am I just trying to make it fool proof, as in what if there happens to be 7 or n + 1 matches then it has to be an array of 7 elements, and since my array is one of the first things I would declare I would not be able to change it.

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Keeping track of found objects in array and smallest value

    Create the new array WHEN you know how large it needs to be. The new code I've described would replace this statement:
    valueFound.length = count;

    After the copy was made, valueFound could be assigned the new array.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 0
    Last Post: October 25th, 2013, 03:28 PM
  2. [SOLVED] Keeping Track
    By Nuggets in forum Loops & Control Statements
    Replies: 2
    Last Post: April 15th, 2012, 05:37 PM
  3. keep track of objects
    By keep smiling in forum Java Theory & Questions
    Replies: 4
    Last Post: February 20th, 2012, 03:44 PM
  4. 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
  5. Keeping objects in webservice
    By ashleypursglove in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 16th, 2010, 12:02 PM