List to Array with Type

Hi guys,
I need to turn a List (an ArrayList specifically) into an array of Components.
This is because I can't call a function like doSomething(Component ... components) with a collection. It needs to be an array correct?
So, if it needs to be an array, I can't find a clean way to do it....or maybe I'm just a whiner.
I can do this with
theList.toArray(new Component[theList.size()]);or I can do it with
(Component[])theList.toArray()But I don't like either of those...why should I have to pass an array in the first one and why should I be the one doing the cast in the second one?
Shouldn't the ArrayList know how to return a correctly typed array?
I wrote this little static method that I put in a helper class...does anything like this exist in the Collections class as a static method?
I couldn't find anything like it in Arrays, or Collections etc.
public static <T> T[] collectionToArray(Collection<T> l){
    Object ret[] = new Object[l.size()];
    int i = 0;
    for(T t : l){
        ret[i++] = t;
    return (T[]) ret;
}If there is a better way to do this please let me know.
Thanks,
~Eric

ganeshmb wrote:
It wasn't done because you either need an array of the proper type passed as a parameter, or a Class<T> passed as a parameter.Why? ArrayList is parametrized, which means it should be able to figure the data type by inspecting its contents, right? The only problem I see is, when its contents are empty, it will have to return null instead of an empty array. This is a different behavior from toArray, but should be acceptabe given the ease of use for clients - they don't have to pass an array instance to get the list back as an array.Wrong. In addition to the empty array behavior, suppose I have an List<Map>. I could have HashMap, ConcurrentHashMap, Properties, etc, all in this list. I still want a Map[] returned. What if my list is filled with HashMap? I still want a Map[] returned. Inspecting the contents is not a workable solution.

Similar Messages

  • UISelectMany :  must be of type List or Array (ERROR with rich:pickLisT )

    Hi
    I have a problem with my <rich:pickList> I can't display the items. When executing the application I got the following error:
    java.lang.IllegalArgumentException: ValueBinding for UISelectMany :  must be of type List or Array
            at org.richfaces.utils.PickListUtils.findUISelectManyConverter(PickListUtils.java:59)
            at org.richfaces.utils.PickListUtils.findUISelectManyConverterFailsafe(PickListUtils.java:79)as the error message the selectItems is not a List but it is I can't understand.
    I transmit to you my backing bean
    @Stateful
    @Name("adminAction")
    @Scope(ScopeType.SESSION)
    public class AdminActionBean implements AdminActionLocal {
    @In(required=false)
       private List<String> customersChoice;
    @Out(required=false)
       private List<String> companyNames;
    @Factory("companyNames")
       public void selectCompanyNames(){
           setCompanyNames((List<String>) getEm().createQuery("select c.companyName from Customer c")
                        .getResultList());
    //getter() and settter...... my .xhtml page
    <rich:pickList id="customersChoice" value="#{customersChoice}">
                        <f:selectItems  id="companyNames" value="#{companyNames}" />
              </rich:pickList>Have you got any Idea. thanks for help
    regards
    bibou

    You might look up the SelectItem, as the value parameter for a f:selectItems must be a List<SelectItem>. Each SelectItem has both a value and a label.
    Or, you could use Tomahawk's t:selectItems which uses a more dataList-style attribute set to allow you to have the value be any List, and you can select items in the List's node to be the Label and the Value of the select option.
    Look em up, they're useful.

  • How to make a list item field with DATE data type?

    I have a column with DATE data type. Using forms 6i I want to generate a poplist list item field with this column while the value of the elements in the list to will be day names like SATURDAY,SUNDAY,MONDAY. if we change the data type from date to char, it will work properly but now with DATE data type behind it, it gives the following error message
    "FRM-32082: Invalid value for given item type.
    List WEEKREST
    Item: WEEKREST
    Block: EMPRESTS
    Form: MODULE3
    FRM-30085: Unable to adjust form for output."
    Using forms 6i how to make a list item field with DATE data type which can hold day names?

    Set your date column as a hidden (non-displayed) field. Create your list item with the varchar2 day names. Create the list item as a non-base-table field that accepts the text values of day names. On that field, create a when-validate-item trigger that translates the text into a real date, which it then uses to set the value of the actual base-table item.

  • No lists or libraries with InfoPath content types can be found.

    I published an InfoPath form to two libraries in the site, one was a document library and one to a form library. I am using the InfoPath Web Part in the same sight and when I open the toolpane, I get the following message:
    No lists or libraries with InfoPath content types can be found. Use Microsoft InfoPath
    to design a form template for InfoPath Forms Services and publish it to a SharePoint library or list.
    Can you help?

    Looks like it has been a while since this post.  Hope this helps someone still facing this problem.
    If you're publishing the InfoPath form as a Content Type:
    Make sure that the Library (Form Templates) where the form is being published to has Content Types enabled.
    Check that the Library where form is being saved upon submittal (if different from above, as it should be) has Content Types enabled.
    The newly published form Content Type added the Library where forms are submitted.
    If you're publishing the InfoPath form without a Content Type:
    Just make sure that the Library you're publishing to is a Forms Library.
    Enjoy!
    Thank you in advance!

  • List of materials with respect to Class type/

    Dear all,
    In which Tcode or table can i find the list of materials with respect to any class type ?
    Table name for Batch Class ?
    or
    How to find KLART ?
    Edited by: Shailesh2510 on Feb 22, 2010 10:55 AM

    hiii
    To get the class type and class , go to table TCLA or TCLAT.
    And one more thing , here standard system , there is transaction code to get class wise materials list.
    If u want u can cevelop custom reports with help of ABAPer.
    If u give the functional details to technical consuiltant , they easily build the report how ever and what ever u want in custom transaction code.
    Any clarification revert,.

  • Getting arrays with same types

    Hi,
    I'm writing an application and at a certain point I need to be able to compare constraints of the same type to see if there are any conflicts.
    At first you get an array with all kinds of constraints in it, not sorted and not knowing wich types are in there. I wrote a comparator to sort the array, which works. After sorting I count the different types there are. Now I would like to make a vector for each type and fill these vectors with the constraints, but I'm not sure how I can do this.
    What I have so far is:
    //first the array of preferred constraints is being examined,
    //if there are conflicts: arbitrarily one of both
    //preferred constraints is being eliminated
    Arrays.sort(pref,new ConstraintTypeComparator());
    //conflicts are only possible between constraints of the same
    //type so after sorting, we get vectors of simillar constrainttypes
    for(int i = 0; i < pref.length; i++){
       //count how many different types there are in the array
       int countTypes = 1;
       for (int j = 0; j < pref.length - 1; j++){
        if(! pref[j].getConstraintType().equals(
            pref[j+1].getConstraintType ())) countTypes++;}
    //make vectors with only constraints of the same type in them
    //for each type there is
        for (int k = 0; k < countTypes; k++){                 
            //not sure how to do this
    [\code]
    Is there an easy way/method I can use to create (and fill) these vectors?
    thanks

    Very funny, but doesn't help one bit...
    You don't know in advance how many types there will be, so in your code indeed if you have more than three: panic(); not only you don't know how many types there will; you also don't know which types there will be. The type of a constraint is a string though, so you could get, save and compare them...
    Isn't there a way to do something like:
    for (int i = 0; i < length; i++){
      Vector type+i+ = new Vector;
    //blalba
    [\code]

  • Billing due list  gettnig updated with unwanted Invoice type

    Hi SAP Guys,
    Using VF04, i get a Billing due list. The issue is - I don't want a particular invoice type to be seen in the Billing due list though that invoice type exists and has different purpose.
    Please, advise.

    hi,
    pl do it this way
    1) go to VF04 t.code
    2)enter the selection criteria as required to carry out the billing process.
    3) then the second field in the VF04 selection screen, you have billing type field > on the right side you have an arrow > clikc to open it > on the top you will find two green light and two red lights > here you have options to select or exclude
    a) a range of billing doc types
    b) single values.
    4) now go the red light single values and give the billing type which you dont want to invoice.
    5) click the execute button there.
    6) Now all the screen selection is done
    7)Now click the save button > it will ask do you want to maintain billing due list > click yes > give a name and save it.
    8) now you have created a varaint for VF04.
    9) Execute the due list.
    regards
    sadhu kishore

  • "In initializer for 'mxmlContent', type Object is not assignable to target Array element type..."

    Hi all,
    So I've have built an application on flash builder 4.5 using Christophe Coenraets' tutorial "Building an EmployeeDirectory" (http://www.adobe.com/devnet/flex/articles/employee-directory-android-flex.html#articlecont entAdobe_numberedheader).
    I'm getting this error message "In initializer for 'mxmlContent', type Object is not assignable to target Array element type mx.core.IVisualElement." and then the debugger highlights my code this line of my code "</s:List>" in my EmployeeDetails.mxml file. This started after I coded Part 5, Step 2 "Integrating with the Device Capabilities: Triggering the Actions".   The rest of the code debugged fine.
    I think it relates to Christophe's note "Note: Make sure you import spark.events.IndexChangeEvent (and not mx.events.IndexChangedEvent) for this code to compile.".  I don't know where to place this
    " import spark.events.IndexChangeEvent;" line of code. 
    Any help?  Tks in advance..
    Any help would be greatly appreciated.  Thanks

    You have a DataGrid directly inside a State element. Perhaps wrap it in an AddChild element?
    More information on using states can be found here:
    http://livedocs.adobe.com/flex/3/html/help.html?content=using_states_1.html

  • Failed MDADM Array With Ext.4 Partition

    Hi Guys,
    I had a powerfailure and now my MDADM array with Ext4 partition is broken.
    The array has now rebuilt but I still can't mount.
    sudo mdadm -D /dev/md0
    [hodge@hodge-fs ~]$ sudo mdadm -D /dev/md0
    /dev/md0:
    Version : 0.90
    Creation Time : Sun Apr 25 01:39:25 2010
    Raid Level : raid5
    Array Size : 8790815232 (8383.57 GiB 9001.79 GB)
    Used Dev Size : 1465135872 (1397.26 GiB 1500.30 GB)
    Raid Devices : 7
    Total Devices : 7
    Preferred Minor : 0
    Persistence : Superblock is persistent
    Update Time : Sun Aug 8 07:30:06 2010
    State : clean
    Active Devices : 7
    Working Devices : 7
    Failed Devices : 0
    Spare Devices : 0
    Layout : left-symmetric
    Chunk Size : 128K
    UUID : 44a8f730:b9bea6ea:3a28392c:12b22235 (local to host hodge-fs)
    Events : 0.1307880
    Number Major Minor RaidDevice State
    0 8 81 0 active sync /dev/sdf1
    1 8 97 1 active sync /dev/sdg1
    2 8 113 2 active sync /dev/sdh1
    3 8 65 3 active sync /dev/sde1
    4 8 49 4 active sync /dev/sdd1
    5 8 33 5 active sync /dev/sdc1
    6 8 16 6 active sync /dev/sdb
    sudo mount -a
    [hodge@hodge-fs ~]$ sudo mount -a
    mount: wrong fs type, bad option, bad superblock on /dev/md0,
    missing codepage or helper program, or other error
    In some cases useful info is found in syslog - try
    dmesg | tail or so
    sudo fsck.ext4 /dev/md0
    [hodge@hodge-fs ~]$ sudo fsck.ext4 /dev/md0
    e2fsck 1.41.12 (17-May-2010)
    fsck.ext4: Group descriptors look bad... trying backup blocks...
    /dev/md0: recovering journal
    fsck.ext4: unable to set superblock flags on /dev/md0
    sudo dumpe2fs /dev/md0 | grep -i superblock
    hodge@hodge-fs ~]$ sudo dumpe2fs /dev/md0 | grep -i superblock
    dumpe2fs 1.41.12 (17-May-2010)
    Primary superblock at 0, Group descriptors at 1-524
    Backup superblock at 32768, Group descriptors at 32769-33292
    Backup superblock at 98304, Group descriptors at 98305-98828
    Backup superblock at 163840, Group descriptors at 163841-164364
    Backup superblock at 229376, Group descriptors at 229377-229900
    Backup superblock at 294912, Group descriptors at 294913-295436
    Backup superblock at 819200, Group descriptors at 819201-819724
    Backup superblock at 884736, Group descriptors at 884737-885260
    Backup superblock at 1605632, Group descriptors at 1605633-1606156
    Backup superblock at 2654208, Group descriptors at 2654209-2654732
    Backup superblock at 4096000, Group descriptors at 4096001-4096524
    Backup superblock at 7962624, Group descriptors at 7962625-7963148
    Backup superblock at 11239424, Group descriptors at 11239425-11239948
    Backup superblock at 20480000, Group descriptors at 20480001-20480524
    Backup superblock at 23887872, Group descriptors at 23887873-23888396
    Backup superblock at 71663616, Group descriptors at 71663617-71664140
    Backup superblock at 78675968, Group descriptors at 78675969-78676492
    Backup superblock at 102400000, Group descriptors at 102400001-102400524
    Backup superblock at 214990848, Group descriptors at 214990849-214991372
    Backup superblock at 512000000, Group descriptors at 512000001-512000524
    Backup superblock at 550731776, Group descriptors at 550731777-550732300
    Backup superblock at 644972544, Group descriptors at 644972545-644973068
    Backup superblock at 1934917632, Group descriptors at 1934917633-1934918156
    sudo e2fsck -b 32768 /dev/md0
    [hodge@hodge-fs ~]$ sudo e2fsck -b 32768 /dev/md0
    e2fsck 1.41.12 (17-May-2010)
    /dev/md0: recovering journal
    e2fsck: unable to set superblock flags on /dev/md0
    sudo dmesg | tail
    [hodge@hodge-fs ~]$ sudo dmesg | tail
    EXT4-fs (md0): ext4_check_descriptors: Checksum for group 0 failed (59837!=29115)
    EXT4-fs (md0): group descriptors corrupted!
    EXT4-fs (md0): ext4_check_descriptors: Checksum for group 0 failed (59837!=29115)
    EXT4-fs (md0): group descriptors corrupted!
    Please Help!

    Give a tip here is somewhat delicate. Perhaps a tip works perfect in some cases and in one case only worsen the situation.
    Have you tried to send an email to linux-ext4 mailing list? There are lots of people involved that may help. http://vger.kernel.org/vger-lists.html#linux-ext4
    I hope that you recover all your information.

  • How to get a vendor list for a event type in training and events

    Hi
    i need to get a vendor list for the event type.
    is there any function module to get the vendor name and vendor no if event type is passed.
    kindly help me...
    With regards
    Rusidar.

    Dear Pushpa,
    Transaction Code :SHD0 is working fine.
    Please accept my sincere thanks for your sharing your Knowledge.
    I am able to fulfill my
    Regarding the enhancement, I have not tried.
    Once I will complete, I will award the fulll marks to you.
    With Best Regards,
    Raghu Sharma

  • How to use List of values with bind variables on item?

    Hi
    I made a dynamic list of values with a bind variable as a provider. I tried to run the list, and it worked fine - i filled inn the bind variable when asked for, and i got a list of values to choose from.
    I would very much like to use this list of values as an attribute on a custom made item. My wish is that when creating the item you someplace write the bind variable, and the list will then turn up as wanted. (I could f.ex add the variable as an attribute on the page type)
    I tried to create a custom attribute and assign the list of values to it. It created an error when I then tried to add the attribute to the item.
    Does anyone have any idea on how to solve this?
    Any help appreciated!
    Maja R. Anjer

    Hi
    i am getting error as
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (SELECT meaning, lookup_code,lookup_type
    FROM fnd_lookup_values
    WHERE view_application_id = 200) QRSLT WHERE (lookup_type=:1 AND ( UPPER(MEANING) like :2 AND (MEANING like :3 OR MEANING like :4 OR MEANING like :5 OR MEANING like :6)))
    Thanks
    Mateti

  • ICal for iPhone. View all events as a list without having to type into the earth box.

    iCal for iPhone. View all events as a list without having to type into the earth box.
    On the previous software version I used to be able to view all my calendar events as a list by clicking on the magnifying glass. Now you have to type into the search dialog box for a list to populate. This is very frustrating and annoying because I much prefer the list format to populate everything unless I specify what I am looking for into the search box. Is there a way to view all the events as a list without having to type anything into the search box?

    And you are aware of the possible options for listing the months and having an optional export value for each month.
    For listing the months, you can use a number, a 3 character string, or the full name.
    For the export value, the full name, the 3 character value, the 1-2 number, or the 0-11 JavaScript value.
    I would look at deciding how you want to populate the drop down box and build a one page form with just this field. You can then insert that page into a PDF and copy the field as needed and then delete the inserted page. Or you could create an FDF file to create the drop down box.

  • What is the maximum rows allowed in PLSQL array table type?

    Hi,
    I have a procedure and it contains the cursor which will fetch more than 500 records. And i have 5 output parameters to store the values coming from the cursor. I don't want to store that into custom table. I want to save it one table type array or something like that. Now i want to know what is the maximum storage of array table type? If i store more than 500 data, how will be the performance? Then is there any other way to achieve this? And that should not decrease the preformace.Let me know your thoughts.
    Thanks

    It really depends on what you are planning to do with the records once you return them from your stored procedure, and what client is on the receiving end of the results.
    One option would be to just return a ref cursor and let the client deal with retreiving the rows themselves, whether one by on or by a bulk collect. Another option would be to declare a table of records matching the result set and do a bulk collect into that table type in your procedure and return the table type to the caller. You could also declare a table type for each field in the resultset, bulk collect the records into thos types and return one for each field.
    Personally, I would likely go with returning a ref cursor. Both of the collect the resultset in your procedure and then return collections to the caller methods require memory on the database server to hold the entire resultset and memeory on the client to hold the entire resultset. While 500 records is probably not going to be too bad on memory, if the result set grows, you will run into memory issues at some point.
    John

  • I have read 118 files (from a directory) each with 2088 data and put them into a 2 D array with 2cols and 246384row, I want to have aeach file on a separate columns with 2088 rows

    I have read 118 files from a directory using the list.vi. Each file has 2 cols with 2088rows. Now I have the data in a 2 D array with 2cols and 246384rows (118files * 2088rows). However I want to put each file in the same array but each file in separate columns. then I would have 236 columns (2cols for each of the 118 files) by 2088 rows. thank you very much in advance.

    Hiya,
    here's a couple of .vi's that might help out. I've taken a minimum manipulation approach by using replace array subset, and I'm not bothering to strip out the 1D array before inserting it. Instead I flip the array of filenames, and from this fill in the end 2-D array from the right, overwriting the column that will eventually become the "X" data values (same for each file) and appear on the right.
    The second .vi is a sub.vi I posted elsewhere on the discussion group to get the number of lines in a file. If you're sure that you know the number of data points is always going to be 2088, then replace this sub vi with a constant to speed up the program. (by about 2 seconds!)
    I've also updated the .vi to work as a sub.vi if you wa
    nt it to, complete with error handling.
    Hope this helps.
    S.
    // it takes almost no time to rate an answer
    Attachments:
    read_files_updated.vi ‏81 KB
    Num_Lines_in_File.vi ‏62 KB

  • How to use array or type in "IN" criteria

    Hi all,
    anybody knows how to use group of same datatype data ( array or type ) in SQL statement
    For example
    ls_dept[1] = 'abc';
    ls_dept[2] = 'xyz';
    ls_dept[10] = 'ppr';
    i want to use this group of data in "IN" criteria like
    Select * from department where dept in ('abc','xyz'.....''ppr');
    if anybody know how to use please reply me as soon as possible.
    Thanks,

    I hope you are not suggesting concatenating literals from a web front-end application ;) Is it not what he was saying.. he is getting user input info from an application.. if the user sends multiple values.. he has to build a string with concatenating literals..
    correct me if I am wrong.

Maybe you are looking for