Results 1 to 3 of 3
  1. #1
    udayjava is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default How to access the array elements in an Arraylist of Arrays and then swap the sublist?

    Java Code:
    ArrayList<int[]> data1 = new ArrayList<int[]>();
    		data1.add(new int[4]);
    		data1.get(0)[0] = 0;
    		data1.get(0)[1]=1;
    		data1.get(0)[2] = 2;
    		data1.get(0)[3]=3;
    		data1.add(new int[4]);
    		data1.get(1)[0]=4;
    		data1.get(1)[1] =5;
    		data1.get(1)[2]=6;
    		data1.get(1)[3]=7;
    		
    		for(int[] c : data1){
    			System.out.println(c.toString());
    		}
    Here I created an ArrayList of int arrays and then initialised two arrays. Now I want to print the elements of the arrays and then swap sublist of the arrays. With toString() I am just printing the object. Can anyone please help me out here

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default Re: How to access the array elements in an Arraylist of Arrays and then swap the subl

    What code do you have so far and what problems are you having with it?

    To format the contents of an array for printing, you can use the Arrays toString() method

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: How to access the array elements in an Arraylist of Arrays and then swap the subl

    udayjava, it's bad form to start a new thread with an obviously related problem without replying to responses on an earlier thread.

    Your second thread has been closed. Please conclude this discussion before you start a new thread.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Swap array value
    By irnie1994 in forum New To Java
    Replies: 1
    Last Post: 11-10-2011, 05:06 PM
  2. how can i loop my array swap
    By belfast09 in forum New To Java
    Replies: 3
    Last Post: 06-15-2011, 04:35 AM
  3. Array of Arrays all unique elements
    By dusker in forum New To Java
    Replies: 9
    Last Post: 04-02-2011, 07:21 PM
  4. Cannot swap elements in ArrayList
    By glchau in forum New To Java
    Replies: 4
    Last Post: 05-30-2010, 08:03 AM
  5. Replies: 5
    Last Post: 01-18-2010, 07:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •