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.

Results 1 to 6 of 6

Thread: Java 1.4 Array issues - controlling array size for dynamic usage

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java 1.4 Array issues - controlling array size for dynamic usage

    I am working on a system and restricted to using Java 1.4
    I have some working code but when declaring an Array I am having to set an Array size large enough to provide for now and the future (as Generics such as ArrayLists and Collections don't seem possible until 1.5). The issue is then when I read through the Array my code crashes at the first null value.

    Now I can program to check for the null value and exit the read through, but is there a better way in 1.4? How would you best go about a dynamically sized array in 1.4?

    Snippet:

    String query = "select Partition.* from Partition where Name like 'SS%'";
    if(debug) jcsOut.println("Finding Partitions");

    String[][] partitions = new String[800][3];
    int i = 0;

    for (Iterator it = jcsSession.executeObjectQuery(query, null); it.hasNext()
    {
    Partition p = (Partition) it.next();

    if(debug) jcsOut.println(p.getName());
    partitions[i][0] = p.getName();

    if(p.getName().substring(2,4).equals("BA"))
    {
    //jcsOut.println("MATCH");
    if(debug) jcsOut.println(p.getName().substring(2,4));
    partitions[i][1] = p.getName().substring(2,4);
    if(debug) jcsOut.println(p.getName().substring(5,9).replace( "_","")+p.getName().substring(9).replace("_","-"));
    partitions[i][2] = p.getName().substring(5,9).replace("_","")+p.getNa me().substring(9).replace("_","-");
    } else if (p.getName().substring(0,2).equals("SS"))
    {
    //jcsOut.println("MATCH");
    if(debug) jcsOut.println(p.getName().substring(0,2));
    partitions[i][1] = p.getName().substring(0,2);
    }


    if(debug) jcsOut.println(" ");

    i++;
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Java 1.4 Array issues - controlling array size for dynamic usage

    Please use the highlight tags when posting code.

    What's stopping you from using an ArrayList? They've been around since 1.2.

    If you're asking how to resize an array, a general way to go about it is to create a larger array and copy the smaller array into it.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java 1.4 Array issues - controlling array size for dynamic usage

    Quote Originally Posted by KevinWorkman View Post
    Please use the highlight tags when posting code.

    What's stopping you from using an ArrayList? They've been around since 1.2.

    If you're asking how to resize an array, a general way to go about it is to create a larger array and copy the smaller array into it.
    I'm trying to declare one like this:

    ArrayList p_al = new ArrayList();

    However it's not working. I'm getting this:
    symbol : class ArrayList
    ArrayList p_al = new ArrayList();
    ShellScript_neilan_j.java:user code 5:21:cannot find symbol

    So I'm not sure if it's the Application I'm running Java through but it should support standard Java 1.4 as I understand it

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Java 1.4 Array issues - controlling array size for dynamic usage

    Please post an SSCCE demonstrating exactly what you're doing, as it's hard to tell the problem from a single line.

    If I had to guess, I would say it sounds like you're missing an import statement, but without an SSCCE, a guess is all it is.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java 1.4 Array issues - controlling array size for dynamic usage

    My imports did not include the correct class
    I added in
    import java.util.ArrayList;
    And now it's AOK

    --- Update ---

    So going with ArrayList - is there a way to create a 2-dimensional ArrayList without generics (Java 1.4)?
    This I'm having trouble with....

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Java 1.4 Array issues - controlling array size for dynamic usage

    You can add any Object to an ArrayList, including other ArrayLists. What have you tried?

    Everything you've asked (how to resize an array, how to import an ArrayList, now this) is pretty basic. If you're really in charge of overhauling real code, I'd take a step back and go through some tutorials before you accidentally make the problem worse.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. java computer science array access issues
    By dylanoo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 17th, 2013, 07:43 PM
  2. compile errors when creating a 2nd array the same size as 1st array
    By javaiscool in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 26th, 2013, 09:35 PM
  3. Unsorted Arrays having trouble controlling the array.
    By orbin in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 16th, 2012, 11:20 AM
  4. Help with dynamic array method
    By Nismoz3255 in forum Collections and Generics
    Replies: 5
    Last Post: September 27th, 2012, 12:37 PM
  5. Doubling The Array Size And Randomizing Array Return
    By Pingu00 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: June 27th, 2011, 10:50 AM