Results 1 to 6 of 6

Thread: ArrayList not working

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    ArrayList not working

    Hello,
    I am using an Array list in my code, but the ArrayList is not quit working for me.
    Code:
    ArrayList <ArrayList[]> Path = new ArrayList <ArrayList[]>();
    to create an index, I do
    Code:
    paths.add(new ArrayList[2]);
                                    paths.get(paths.size()-1)[0] = new ArrayList <Integer>();
                                    paths.get(paths.size()-1)[1] = new ArrayList <Integer>();
    What works very well. But I can not get the correct index deletion: If I have 10 index in the ArrayList path, for example, and I will keep only the last 5, I wrote:
    Code:
    for(i =0; i <5; i + +){
       for(j =0j <ways.get(i)[0].size()j + +)
                	paths.get(i).remove(j);
                   
    }
    and the AC did not work. If I write:
    Code:
    for(int g =0g <p g + +){
             paths.get(g)[0].clear();
             paths.get(g)[1].clear();
    }
    The AC works, but the top 5 indexes are always empty, but they still exist, although I wish that the last 5 indexes take up the first 5 and then pass the size to 5 index. Please help

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: ArrayList not working

    Hello,
    I am not sure that your data structure is the most appropriate solution to your problem. Could you say exactly what you want to manage it? Is it a simple list? because that what you created is a list of tables lists. I find it rather special. I think you should try this. If not there are some more solutions for this, but rather I would recommend you this one.

  3. #3
    Join Date
    Nov 2009
    Posts
    335

    Re: ArrayList not working

    Hello,
    My solution will sound you little wired, but I think this makes sense in your code. Have a look at it.
    Code:
    for(i =0; i <5; i + +){
    paths.remove (i); 
    }
    Not sure though that it works very well, because I have not tested it. If you have any more problems then do post back, but before that I think you should try this.

  4. #4
    Join Date
    Dec 2009
    Posts
    192

    Re: ArrayList not working

    Hello,
    I think I should try your solution. I have not tried it yet, but I am not sure that this would fit in my program. By this is of being in bidle.get (machine) [owl]. Get (foo). It sees the simplest, which is often the solution. This is a good alternative for the program code, but I think this will not have more features than if I use some other method here. Thank you.

  5. #5
    Join Date
    Nov 2009
    Posts
    583

    Re: ArrayList not working

    Hello,
    Cool my attention contained a code error as to remove the first 5 elements must be.
    Code:
    for(i =0; i <5; i + +){
    paths.remove (0); 
    }
    I think this is the one you should go for. Just include this part in your code and then test your program and see if it works.

  6. #6
    Join Date
    Dec 2009
    Posts
    192

    Re: ArrayList not working

    Hello,
    And misery is to remove indexes based on a test. Took the lead for 1h before compendium need to put a meter. Either you delete the index is incremented on the computer, and it turns the index counter . Is this called a Dynamic management of ArrayList? Because I do not have much idea about it. So if you give me a more detailed idea about it, it will be helpful for me.

Similar Threads

  1. ArrayList overwriting error
    By Captain Carrot in forum Software Development
    Replies: 5
    Last Post: 26-03-2010, 09:04 AM
  2. Using an ArrayList
    By ISAIAH in forum Software Development
    Replies: 5
    Last Post: 04-03-2010, 12:56 PM
  3. Incorrect return of ArrayList
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 04:34 AM
  4. Multithreading and ArrayList
    By Logan 2 in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 05:16 AM
  5. Initialize an ArrayList
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 04:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,824,193.49767 seconds with 16 queries