Retrieve first element of a Collection

Hello,
How to retrieve only the first element (class) of a Collection?
Thank you
Sylvain

Object firstElement = yourCollection.iterator().next()

Similar Messages

  • Is it possible to bind the first element in a collection in a datagrid?

    I have a datagrid and I need to bind a property in the first element of the collection of my datasource object. By the momento I am using a converter:
    <DataGridTextColumn Header="MyValue" Binding="{Binding Converter={StaticResource myConverter}}"/>
    But I would like to avoid the need to use a converter, so I have tried this:
    <DataGridTextColumn Header="MyValue" Binding="{Binding MyCollectionProperty.ElementAt(0).MyValue}"/>
    Is there any way to do it?

    You cannot call ElementAt(i) from the XAML because it is a method.
    MyCollectionProperty[0] will certainly get you the first value of the MyCollectionProperty collection provided that the type has an indexer.
    If you want to be able to this without using a converter you must change the type of the property from ICollection<T> to for example IList<T>.
    You could create a wrapper property (potentially in a partial class definition) and bind to this one:
    //old property:
    public ICollection<YourType> MyCollectionProperty {
    get;
    set;
    //new wrapper:
    public IList<YourType> MyCollectionPropertyWrapper {
    get {
    return new List<YourType>(this.MyCollectionProperty);
    <DataGridTextColumn Header="MyValue" Binding="{Binding MyCollectionPropertyWrapper[0].MyValue}"/>
    ICollections are not very XAML friendly and you cannot bind to the first item of an ICollection using an indexer or ElementAt(0) or any other direct way.
    Please remember to mark all helpful posts as answer to close your threads.

  • Retrieve Last element from Collection

    Hi,
    I am a beginner in Java. Can somebody tell me how to retrieve last element from java.util.collection without Iterating?

    Hi,
    I am a beginner in Java. Can somebody tell me
    how to retrieve last element from
    java.util.collection without Iterating?You realize of course that this is rather silly since not every Collection necessarily has a "last" element. For it to have the notion of a "last" element it would have be ordered and would be a List.

  • Sort an an arrayList by the first element of an array

    Hi,
    I am really struggling trying to sort an arratList of arrays. I have an arrayList
    ArrayList<String[]> myArrayList = new ArrayList<String []>(100);
    Within this array I have may arrays with 2 elements
    String[] myArray1 = {"Peter", "London"};
    String[] myArray2 = {"John", "London"};
    String[] myArray3 = {"Tony", "Birmingham"};
    I add all these arrays to the arrayList and want to sort by the first element of the array. Basically I expect the final arrayList to be in the order of:
    "John", "London"
    "Peter", "London"
    "Tony", "London"
    Thanks
    Peter

    Hi,
    I am really struggling trying to sort an arratList of
    arrays. I have an arrayList
    ArrayList<String[]> myArrayList = new
    ArrayList<String []>(100);
    Within this array I have may arrays with 2 elements
    String[] myArray1 = {"Peter", "London"};
    String[] myArray2 = {"John", "London"};
    String[] myArray3 = {"Tony", "Birmingham"};
    I add all these arrays to the arrayList and want to
    sort by the first element of the array. Basically I
    expect the final arrayList to be in the order of:
    "John", "London"
    "Peter", "London"
    "Tony", "London"
    Thanks
    PeterThis can be done by using
    Collections.sort(myArrayList, new Comparator<String[]>() {
    public int compare(String[] s1, String[] s2) {
    if (s1.length() <1) {
    return -1;
    if (s2.length() <1) {
    return 1;
    return s1[0].compareTo(s2[0]);
    });

  • How can i retrieve missing element in array

    how can i retrieve missing element in arrays if array length is exceeded

    Not sure about what the question means, but could it be that OP is not aware that the first element in an array is at index 0 (not 1) ?
    <a href="http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html" style="background:url(http://java.sun.com/docs/books/tutorial/figures/java/objects-tenElementArray.gif) no-repeat; width:400; height:145;"></a>

  • How to delete the last element of a collection without iterating it?

    how to delete the last element of a collection without iterating it?

    To add to jverd's reply, even if you could determine the last element, in some collections it is not guaranteed to always be the same.
    From HashSet:
    It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.

  • How to set the focus to a first element in oracle apex 3.2.1  and 3.1.2.00

    Hello ,
    I am using oracle apex 3.2.1 in development env. How to set the focus to a first element of a page.
    thanks/mahesh

    Hi,
    This might help
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/bldr_pgs.htm#CJGJDHCI
    Find "Cursor Focus" from page Display Attributes
    Br,Jari

  • NXSD is missing first element

    Hi ,
    When I test the nxsd generated I see the first element is being used for differentiating the records and it is missing from the output xml.But I want that to appear in the output xml.
    I treid modifying the nxsd to include c1 element manually it didn't helped.
    <xsd:choice minOccurs="1" maxOccurs="unbounded" nxsd:choiceCondition="fixedLength" nxsd:length="4">
            <xsd:element name="RECORD1" nxsd:style="array" nxsd:cellSeparatedBy="${eol}" nxsd:conditionValue="P03A">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="C2" type="xsd:string" nxsd:style="fixedLength" nxsd:length="3" />
    C1 elements declaration is missing from the generated nxsd. I am expecting the value "P03A" to be present in the output xml,during the initial config of nxsd I used these 4 characters to differentiate the records.My records have data PO3A,P03B etc...where the 4th character is the differentiator.The data is being used for identifying the different records in the flat file and it is not appearing in the output xml.

    This is most probably because the Periodicity input value has been configured as "Required" and no value has been input for it.
    Please enter a value and try to re-run Quick Pay.

  • WebService problem: only the first element of a string array is returned

    Hello,
    i did the J2EE QuickCarRental tutorial and extended it by some features: I created another entity bean and implemented four new methods in the QuickOrderProcessor. Then i deployed it as a WebService and accessed it using the Visual Composer.
    Everything works fine except the return value of one WebService method. I created a method with the return value String[]. But the Visual Composer reads it as String. Only the first element of the resulting string array is displayed. Although the test at the web-page http://<server>:<port>/QuickCarRentalService/Config1 displays the whole string array with all its elements. What did i wrong?
    Another problem is that after deploying the J2EE-Application with new WebService methods the changes are not visible inside the visual composer. Although the test at the web-page http://<server>:<port>/QuickCarRentalService/Config1 displays the changes. Do i have to restart the WebService system in the portal content? If yes how can i do that?

    Here are details about setting up and using web services and some examples:
    /people/prakash.darji/blog/2006/10/10/external-web-service-proxy-configuration-for-visual-composer

  • COM: This key is already associated with an element of this collection

    Hello,
    Our system has been upgraded from CRM4.0 to CRM2007 and i have managed the collisions successfully.
    I already have fixed several errors (sometime with the help of this forum...), but i still have the following error which require adjustments.
    I've got this message after the generation of one of my tiles :
    "Generating UITile docactdocu2
    Error: Processing failed: COM: This key is already associated with an element of this collection"
    I found the note from microsoft but i am not sure to understand well :http://msdn.microsoft.com/en-us/library/aa232626(VS.60).aspx
    I do not have any add method in that code. This tile is linked to several other one. Can this error located into an other tile ?
    e, i have to keep the assigment for the Z segment.

    Hi,
    fyi: There are also other SAP owned prefixes e.g. TSR_ for specific enhancements for Mobile Service. So you don't need to care about that objects.
    Also you might notice that some of these event handler "twins" are commented out because the other is still active. And for those where both have a coding it is the same (like "Gate = 1") which doesn't make any problem.
    Probably the other SAP colleagues working for MSA development can explain more in detail but I guess that the red marked event handlers are fired by system events (like load/beforesave) where the user doesn't have any influence.
    The black ones are fired directly after an user action, like "button_onclicked" or "anchoronupdate".
    Regarding your issue you should open the tile in design mode and then open the list next to "custom popups". I guess there are some duplicates which you surely can delete.
    Regards,
    Wolfhard

  • Delete element from a collection (JDev 10.1.2)

    Hello
    I have a bean which has a collection "testCollection" and accessors for it. This has been populated with some elements (similar to the LDAPDataControls example). I have created the data control for it and dragged the collection onto a JSP as a read only form. This displays the current element of the collection depending on the iterator position.
    I then have a forward on the page using a button to a Data Action called RemoveAction. I have overwritten invokeCustomMethod and I'm trying to remove the element in the collection at the current iteraotr position.
    I can access the iterator using actionContext.getBindingContainer().findIterator("testCollectionIterator");
    From this I can get the current row but both row.remove() and row.removeFromCollection throw UnsupportedMethod exceptions.
    I can access the collection using actionBinding.getBindingContainer().getDataControl().getDataProvider(), but I have no way of removing the object from the collection without having a reference to the object itself.
    Please can someone explain how to remove elements from the collection?
    Also can someone explain in the LDAPDataControls example why its also necessary to have a class called LDAPDataControl (type of DCGenericDataControl) and a LDAPDataControlFactory (type of DataControlFactoryImpl)?
    Just having the classes LDAPSearch, the bean class LDAPEntry, and a class to hold the collection LDAPCollection works fine. Create the data control for LDAPCollection and drag the collection onto the JSP.
    Thanks.

    I'm still not sure about this. Can anyone help? Thanks.

  • Shall we compare two elements in a collection

    Dear all,
    shall we compare two scuccessive elements in a collection
    i am creating a type.and i am dumping the data into that type using bulk collect.now i need to compare the data in type (previous value and current value).
    please suggest
    Thank you.
    Suresh

    899511 wrote:
    Dear all,
    shall we compare two scuccessive elements in a collection
    i am creating a type.and i am dumping the data into that type using bulk collect.now i need to compare the data in type (previous value and current value).
    please suggest
    Thank you.
    SureshDon't do it in a collection. Use SQL.
    SQL provides Lead and Lag analytical function that allow you to compare next/previous values.
    e.g.
    http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions070.htm
    Loading the data into a collection in memory to do something that can be easily achieved in SQL is just wrong and uses expensive PGA memory unnecessarily.

  • ArrayList drops the first element

    I hate asking for help, but this has me confused.
    I have a code that outputs the elements of an arraylist as text strings to a file. For some reason, the first element of the ArrayList gets dropped, but every other element after gets saved to text perfectly.
    public void writeOut(ArrayList a)throws IOException{
        String[] out=new  String[a.size()];
        for(int i=0;i<out.length;i++){
            out=a.get(i).toString();
    System.out.println("" + out[i]); //test line to see if element has been moved
    I have also tried:
    public void writeOut(ArrayList a)throws IOException{
        String[] out=new  String[a.size()];
        for(int i=0;i<out.length;i++){
            out=(String)a.get(i);
    System.out.println("" + out[i]); //test line to see if element has been moved
    The code is straight forward, the best I can tell...so what am I overlooking? I am assuming that my array needs to be primed or something first. I suppose I could make the array one bigger and put some bogus value in the first element...That doesn't really seem the right way to do it though.

    I didn't notice it either until I tried to pass it an ArrayList with only one string....I must be having a problem where the ArrayList is being created then.
    And that is exactly where the problem was... :sigh:
    Thanks for checking that for me.

  • Error - The key is already associated with an element of this collection

    Hi,
    After a fresh installation of BPC 5.1 SP3 in a dual-server environment we're getting an SAP error - "The key is already associated with an element of this collection"  after logging into BPC for Excel.
    Has anyone seen this error before or know what is causing it?
    Thanks,
    Glenn Van Der Werff

    We're using SQL Server 2005 Enterprise Edition with Service Pack 2.  We ended up doing the installation on a single server instead of a dual server environment.  The error is no longer happening in the single server environment.
    I'm still curious as to why we were getting the error in the dual server environment if you're seen this before.
    Thanks,
    Glenn

  • Creating XML from XSD, Only create The First Element

    Hi,
    I create a XML File from a xsd schema by this way:
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setNamespaceAware(true);
              factory.setValidating(true);
                   factory.setAttribute(JAXP_SCHEMA_LANGUAGE,W3C_XML_SCHEMA);
                   factory.setAttribute(JAXP_SCHEMA_SOURCE, new File(MY_SCHEMA));   
                    DocumentBuilder documentBuilder =factory.newDocumentBuilder();
              documentBuilder.setErrorHandler(new SimpleDOMHandler());
              Document parse = documentBuilder.parse(new File(MY_XML));The first lines of the schema:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
         targetNamespace="http://gencat.net/scsp/esquemes/peticion"
         elementFormDefault="qualified" attributeFormDefault="unqualified"
         id="Peticio" xmlns:p="http://gencat.net/scsp/esquemes/peticion">
         <xs:element name="Apellido1">
              <xs:simpleType>
                   <xs:restriction base="xs:string">
                        <xs:maxLength value="40" />
                   </xs:restriction>
              </xs:simpleType>
         </xs:element>
         <xs:element name="Apellido2">
            .............................The problem is that the created document only have the first element "Apellido1". I dont know if it is a wrong xsd, or i'm using a bad way to do it.
    Thanks a lot, and apologize for my english

    Hi,
    Is it possible to create and populate XML from an XSD
    without knowing what the XSD elements are beforehand
    (all the examples appear to know what the input XSD
    will be, and therefore know what the set and get
    methods should be called)? I think it is possible--you would have to recompile each time (unless you can dynamically recompile, which would be neat), but using the classes getMethod() function, you can list all the methods. You would then have to do some tricky logic to determine which of the getMethods you want (for example NOT getClass()), and you can basically call them in sequence. You also need to worry about handling lists & recursively call xxxType classes.
    I'm experimenting with this, and it can get a little frustrating because there are a lot of odd cases to handle (for example, while setting the elements of a list, you need to actually get the list & add elements to it), but I think it's possible.
    >
    Can a user browse for an xsd to input, and the java
    will dynamically create the get methods, and be able
    to create instances and populate variables before
    converting to XML?
    What I'm puzzled about is where you'd get the data to populate the variables? Perhaps a database, or a bean? If you just want to make a test xml file, then it doesn't matter, but with real data, I think you'd still have to change how you actually get the variables you want to populate the xml file with, right? In other words, if your schema changed, the parameters you're passing to the set methods would change as well.
    Maybe we'll see some more packages in the future to make this task easier.

Maybe you are looking for

  • MS word .doc or .docx attachments won't send or receive in Thunderbird

    I'm running Mac OS X 10.9.5 and Thunderbird 31.5.0. When I attach a .doc or .docx file in Thunderbird to an outgoing message, the attachment disappears. The outgoing message sends as normal, but when I go into my sent folder, there's no attachment, a

  • Error message very vexing

    Hi there, i need serious help.my powerbook started giving me a very annoying message "Assertion (false) failed "proxy.c", line 221" .honestly i am not concerned how it got there, i really need it off,because none of my music applications (Dp4.6,Ablet

  • Deactivating  a particular Account Assignment Category for a Pur. Orgn.

    Hi,   We want to deactivate a particular account assignment category for a particular purchasing organisation. Can any one please throw some light on it??

  • USage of URL iView

    Hi All, How can we use the URL iView, in the process of portal branding. Regards Seshu

  • Idvd menu playback

    Hi I have two questions/issues with iDVD. I'm a bit of a beginner when it comes to iDVD but I have checked all over the internet for the answers. First I am using the soft frame theme and I am using all three drop zones with video filling them. When