Results 1 to 6 of 6

Thread: Change value of the list in ArrayList

  1. #1
    Join Date
    Dec 2009
    Posts
    296

    Change value of the list in ArrayList

    Hello,
    I have an ArrayList which contains L1 ArrayList. How do I change the value of a list L1 in the 2nd example
    list1 contains
    [[orange] [orange] [orange]]
    And I want to add the mango 2nd list [orange] by [orange, mango]
    Code:
    List l2 = new ArrayList();
    l2 = (ArrayList) l2.get(1);  / / 1 because it counts from 0
    l2.add("Mango");
    I find myself with
    [[orange1, mango], [Orange, Mango], [orange, mango]]
    It adds orange everywhere. I was wondering that I could change the value of the list in the arraylist. is this possible and if yes then I am interested.

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: Change value of the list in ArrayList

    Hello,
    Are you sure the names of your variables in your code, there as no l1 and l2. Otherwise, it would:
    Code:
    ((List)l1.get(1)).add("Mango");
    Just check your code and then again run the program and if it gives you an error post the error here. I request for the error because the error helps us find he exact problem in the code. Just do this and if you have more problems then you an post back.

  3. #3
    Join Date
    Dec 2009
    Posts
    296

    Re: Change value of the list in ArrayList

    Hello,
    Here is my updated code, please hava look at it and if you find some problems in it then guide me or correct me with the same.
    Code:
    List l2 = new ArrayList();
    l2 = (ArrayList) list1.get(1);  / / 1 because it counts from 0
    l2.add("Mango");
    If you have any alternate solution then i am a interested candidate. Thanks in advance.

  4. #4
    Join Date
    Nov 2009
    Posts
    446

    Re: Change value of the list in ArrayList

    Hello,
    When creating your l1, you of doing something like:
    Code:
    List l2 = new ArrayList();
    l2.add("orange");
    List l1 = new ArrayList();
    l1.add(l2);
    l1.add(l2);
    l1.add(l2);
    try something like this
    Code:
    List l2 = new ArrayList();
    l2.add("orange");
    List l1 = new ArrayList();
    l1.add(l2);
    l1.add(new ArrayList(l2));
    l1.add(new ArrayList(l2));
    well, you have different lists all together.

  5. #5
    Join Date
    Dec 2009
    Posts
    296

    Re: Change value of the list in ArrayList

    Hello,
    Not actually my l1 is empty at the beginning and I travel a loop to complete and add items to some of listes2. The Code is plux I used the complex, such as oranges to illustrate the problem. Can you see my previous discussion, Initialize an ArrayList this problem the y follows. I think the solution you can is not much helpful for me. I want an alternate solution for this. if you have one then please post back it will be great for me.

  6. #6
    Join Date
    Nov 2009
    Posts
    583

    Re: Change value of the list in ArrayList

    Hello,
    Here is another example. The idea is that when you filled your list1 you do that adds new lists to avoid putting the same. Basically, it would chose in kind:
    Code:
    List l1 = new ArrayList();
    for (int i = 0; I <taill1; i + +) {
       l1.add(new ArrayList());
    }
    Hope this helps you. Try it and if you have problems then you can ask.

Similar Threads

  1. Unable to change mail list font in Mac OS X Lion
    By Mia! in forum Windows Software
    Replies: 10
    Last Post: 10-11-2011, 10:44 PM
  2. How to Change Window's Explorer Jump List?
    By MahA ChOK in forum Windows Software
    Replies: 3
    Last Post: 03-11-2010, 01:51 AM
  3. Add Change Default Folder In Look In List
    By Mr.Walter in forum Windows XP Support
    Replies: 2
    Last Post: 25-10-2010, 10:40 AM
  4. Details vs List view- how to change default?
    By Lathar in forum Windows XP Support
    Replies: 1
    Last Post: 30-10-2007, 08:49 AM
  5. Name change not showing up in Global Address list
    By IJAYA in forum Small Business Server
    Replies: 1
    Last Post: 29-03-2007, 01:24 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,713,940,105.16006 seconds with 17 queries