Results 1 to 3 of 3
  1. #1
    maxim is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default return Set .toArray(); method as an array of integers

    First off hello everyone.

    as you can see i have declaed a "Set" called "dupes" assume it has values

    i have a function to get this set. its called getDupes();

    i want getDupes(); to return this set as an array via the set.toArray(); method. but i am totally confused as to the documentation on this.

    by default the .toArray(); method seems to return an array of type Object[]. how would one return this array of type int[] as all values in this set are of type int[]

    heres the code.

    Java Code:
    private Set<Integer> dupes = new HashSet<Integer>();
    ...
    ...
    public int[] getDupes() {
        return this.dupes.toArray();
    }

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    After you receive a value at "Set to array of objects"....

    try to convert that object to a String.....
    after you have that string,
    Convert in into Integer type value....

    kind regards,
    sukatoa

  3. #3
    maxim is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default

    oh seems like a bit of xtra effort. ill just leave it as an array of type object for now.

    i just thought there was a parameter i could pass to the .toArray(); method that would let me specify the type

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2010, 08:05 PM
  2. return a null method
    By valoyivd in forum New To Java
    Replies: 2
    Last Post: 04-21-2008, 11:19 PM
  3. Replies: 1
    Last Post: 02-16-2008, 09:10 PM
  4. Return question in a method.
    By MetalGear in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 04:45 AM
  5. Return value of method
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 08:23 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
  •