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 3 of 3

Thread: Extracting an How to ArrayList from an ArrayList and convert to int??

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    18
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Extracting an How to ArrayList from an ArrayList and convert to int??

    Hi,
    I have a method which creates ArrayLists and stores them within an ArrayList as follows:

    ArrayList<ArrayList<Integer>> clusters = new ArrayList<ArrayList<Integer>>();
    ArrayList<Integer> set = new ArrayList<Integer>();
    set.add(supportTemp); // supportTemp is an int
    clusters.add(set);
    I know clusters.get(0) will return the first "set" which was added, but i'd like to then convert this to an integer array. I've tried various methods from googling and reading the API, but am completely stuck on this. Any help would be appreciated.


  2. #2
    Junior Member
    Join Date
    Jun 2009
    Posts
    18
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Re: Extracting an How to ArrayList from an ArrayList and convert to int??

    Done it, here's how...

            ArrayList set = new ArrayList();
            List newList = lists.get(0);
            set.add(newList);
            Object[] predators = newList.toArray();
            Integer objectInteger = (Integer) predators[0];
            int test = objectInteger.intValue();
            System.out.println("Pred: " + test);

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Extracting an How to ArrayList from an ArrayList and convert to int??

    Glad you worked it out

    // Json

Similar Threads

  1. How to use an ArrayList and what is its advantage over array?
    By JavaPF in forum Java SE API Tutorials
    Replies: 4
    Last Post: December 21st, 2011, 04:44 AM
  2. ArrayList Problem
    By Marty in forum Collections and Generics
    Replies: 16
    Last Post: August 31st, 2010, 04:47 AM
  3. Multi-dimension ArrayList example
    By helloworld922 in forum Java Programming Tutorials
    Replies: 1
    Last Post: February 3rd, 2010, 11:01 AM
  4. convert arraylist to a hash map
    By nadman123 in forum Collections and Generics
    Replies: 1
    Last Post: July 29th, 2009, 05:24 AM
  5. Converting a method from ArrayList so it is capable with an Array
    By BlueJ1 in forum Collections and Generics
    Replies: 2
    Last Post: July 8th, 2009, 06:22 PM