Implementation of toArray(Object[] a)

I'm having trouble grasping one small aspect of the method, specifically:
"Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection."
As I understand it, if a user passes in an array of String objects and the array is not long enough, I need to allocate a new array of String objects, and not just simply an array of Objects. How exactly would I go about instantiating an array of objects of a specific type that is determined at runtime?

You can look in the src.zip to see how this is done for ArrayList:
public Object[] toArray(Object a[]) {
    if (a.length < size)
        a = (Object[])java.lang.reflect.Array.newInstance(
                                a.getClass().getComponentType(), size);
    System.arraycopy(elementData, 0, a, 0, size);
    if (a.length > size)
         a[size] = null;
    return a;
}

Similar Messages

  • Hide or display Implementation Tab in object the PACKAGE

    Hi!
    How I can hide or display a "Implementation Tab" in object the PACKAGE for other users?
    OWB 11.1.0.7.0
    Thanks!
    Edited by: user12277289 on 7/12/2009 6:20

    You can wrap your code if you dont want anyone to see it.

  • Can anyone clarify me about the api Object[] toArray(Object[])

    There are two apis in Collections framework to convert the Collection elements into an array
    1. Object[] toArray()
    2. Object[] toArray(Object[])
    Can some one explain me what does the second api - Object[] toArray(Object[]) does ?

    Just read the javadoc API of the Collection interface: toArray() just returns an Object[]. But if you need for example a String[] as result use
    String[] sa = o.toArray(new String[0]);

  • Implement a View Object with multiple entity objects

    Hi
    In 'How to' section on the 'otn.oracle.com' (Jdeveloper) web site is tutorial how to implement a View Object with multiple updateable dependent entity objects.
    It allows user to insert an employee and a department at the same time.
    But I would like to change this example to insert a new department only if it does not already exist. How to change this sample?
    Is there any other way to this?
    Thanks
    Regards
    Gorazd

    Once again the structure, sorry.
    ViewObject
    |-ParentEntityObject
    ..|-PId
    ..|-PAttribute
    ..|-CId (FK)
    |-ParentChildAssociation
    |-ChildEntityObject
    ..|-CId
    ..|-CAttribute
    Christian

  • Drill function implemented on Measure object column in the webi report

    Post Author: madan kumar
    CA Forum: WebIntelligence Reporting
    Hi,
    I have a small issue in my project.(Maintenance Project)I created a measure object in the fact table of the existing universe and saved and exported to the repository. (Say Measure object is D where D = A-(B+C))I inserted the same object as a column between two measure objects columns of a existing WebI report.
    The report has two hierarchies involved  - each hierarchy has dimension objects involved.I have checked with the hierarchies to make sure that measure object is not involved.The scope of analysis is None for the query.Version is BO XI R2.
    The issue is the Drill function is implemented on that particular new column.The drill function should be applicable only to the two dimension objects involved in the report.But this measure object column is also getting drilled once the Drill option is selected.I had to remove the drill optiion from the Measure object column.
    Can anyone help me on this issue...
    Thanks in advance...
    Madan Kumar

    Sushil
    Thanks for your reply. I did the date diff on the columns. It does not  break into 3 different groups. I am using a function called previous on the date column. So the report is like this
        DATE                           Pervious (DATE)                 Date - Pervious(DATE)
    01-01-2008 01:06              Null                                
    01-01-2008 01:12              01-01-2008 01:06               :06
    01-01-2008 01:18              01-01-2008 01:12               :06
    01-01-2008 01:24              01-01-2008 01:18               :06
    01-01-2008 01:30             01-01-2008 01:24              :06
    01-01-2008 01:36             01-01-2008 01:30               :06
    Basically we are breaking on the Date - Previous ( Date) column which does not work. I am not sure if there is a way to break this. I even tried it in Crystal REports XI and it does not work their either. Any help with this issue with be greatly appriciated.
    Edited by: Srinivasa Prabu on Aug 4, 2008 2:55 PM
    Edited by: Srinivasa Prabu on Aug 4, 2008 2:56 PM

  • How to implement a Session Object.

    Hi,
    If anybody show me any example of how to implement
    session object so that I can store any parameters such as user id and use it later on. And also if there is any good web site for reference about using session object.
    thanks

    You can use the the session.setAttribute and session.getAttribute methods.
    For example let's say you would want to store a username in the session after a user has logged on:
    String usrname = request.getParameter("username");
    session.setAttribute("myStoredUsername", usrname);
    you can then retrieve it using the get method. Remember that the entities stored inside a session object are generic objects and need to be cast to be used:
    String usrname2 = (String)session.getAttribute("username");
    Hope this helps
    Chelman

  • List implementation where remove(Object) is fast?

    Does anyone know of an implementation of the java.util.List interface where the the method boolean remove(Object o) is much faster than traversing through the list until it finds the right one? Perhaps something that takes advantage of the hash code of the object being removed?
    Thanks

    So you want a List that acts like a Map?
    Couldn't you just use a Map?
    Explain your problem domain better and we shall help
    you see the light.
    Well no - I would simply like a List that acts like a List, and whose remove(Object) method is faster than just scanning through each element.
    I only mentioned use of the hash code as one way this could be implemented. To expand on that: Currently the LinkedList class internally maintains a list of Entry objects. Each of these objects has a reference to the previous and next Entry and the 'current' list element object. The problem is that the remove(Object) method has to go through each Entry one by one, searching for a list element that equals the object to be removed. To fix this problem the list implementation could also maintain a HashMap whose 'keys' are the list elements and whose 'values' are a (secondary) list of Entry objects associated with that key. Now the remove(Object) method could use the object to be removed to look up the 'list of associated Entry objects'. The first Entry in this (secondary) list is the one that needs to be removed.
    But perhaps it's best if I describe the overlying problem: I want to write a program that randomly generates integers at the rate of about 10 per second. For each integer the program should calculate how many times in the past hour that number has been generated. What's the fastest way to calculate this?

  • Implementing the CompareTo(Object T) method of interface Comparable T

    Hi,
    I cannot figure out how to write implementation to compare two objects for the CompareTo method.
    I have an Employee class and a Manager class that inherits Employee and in the main method i want to sort the objects so that i can use the method binarySearch(Object[] a, Object key), originally i sorted each object in order of their salaries but i now need to be able to distinguish between a Manager object and an Employee object.

    demo:
    class Base implements Comparable<Base> {
        private String baseField;
        @Override public int compareTo(Base that) {
            return this.baseField.compareTo(that.baseField);
    class Derived extends Base {
        private String derivedField;
        @Override public int compareTo(Base that) {
            int result = super.compareTo(that);
            if (result == 0 && that instanceof Derived) {
                Derived thatThang = (Derived) that;
                result = this.derivedField.compareTo(thatThang.derivedField);
            return result;
    }Base objects are ordered by baseField. (I assume all fields will be non-null, for simplicity.) Between Derived objects with equal baseField, I order them further by derivedField.
    edit. I should mention that there are headaches that usually follow when you compare objects of different types. Suppose you have three objects:
    obj1, a Derived object with baseField = "b", derivedField = "x"
    obj2, a Base object with baseField = "b"
    obj3, a Derived object with baseField = "b", derivedField = "y"
    according to the compareTo methods, obj1 and obj2 are equal, and as well, obj2 and obj3 are equal, but obj1 and obj3 are not equal, so we do not have transitivity. ;-(

  • Implement new authorization object in MRBR (SU24)

    Hi,
    I'd like to add a new authorization check in transaction MRBR.
    I tried with SU24 -> MRBR -> adding object M_RECH_BUK with "CM" check ID.
    When testing : nothing appened (no check made).
    After reading all SDN posts about SU24, i think i'd to implement an "authority-check" on M_RECH_BUK in MRBR coding. And i don't like this....
    Do you think i can do this check in MRBR using user-exit ?
    Thanks a lot for your response.
    Etienne

    Hi,
    Below are the User-Exits for the T.CODE MRBR
    Exit Name           Description                                                                               
    <b>LMR1M001</b>            User exits in Logistics Invoice Verification                 
    <b>LMR1M002</b>            Account grouping for GR/IR account maintenance               
    <b>LMR1M003</b>            Number assignment in Logistics Invoice Verification          
    <b>LMR1M004</b>            Logistics Invoice Verification: item text for follow-on docs 
    <b>LMR1M005</b>            Logistics Inv. Verification: Release Parked Doc. for Posting 
    <b>LMR1M006</b>            Logistics Invoice Verification: Process XML Invoice          
    <b>MRMH0001</b>            Logistics Invoice Verification: ERS procedure                
    <b>MRMH0002</b>            Logistics Invoice Verification: EDI inbound                  
    <b>MRMH0003</b>            Logistics Invoice Verification: Revaluation/RAP              
    <b>MRMN0001</b>            Message output and creation: Logistics Invoice Verification  
    it is better if you write a Field exit on the Field <b>M_RECH_BUK</b>
    For the Field exits,
    http://www.sapgenie.com/abap/fieldexits.htm
    http://www.sap-img.com/abap/field-exits-smod-cmod-questions-and-answers.htm
    Thanks
    Sudheer

  • Implementing a view Object with Multiple Updateable Dependent Entity Objects

    Hello,
         I want to implement view object with multiple updateable entity object,
         i have refered this link its good https://forums.oracle.com/thread/63721
         here they have explained with 2 table,
         but when we have more then 5 tables and each table have Primary keys , Foreign key , Sequence and  trigger created on it. Then whats steps should i want to fallow.
         if possible some please provide the link or some one help me out how to do this .
         thanks in advance
         cheers

    Has the Advanced View Object Techniques been referred?

  • List.toArray(Object[])

    Question :
    Why does this not work
    public String[] void somemethod()
    String str[] ;
    ArrayList list= SomeObject.getPopulatedList();
    return (String[])list.toArray(str)
    Should'nt toArray method create a instance of String[] is str == null.
    why do I need to create new String[size] before I call (String[])list.toArray(str)

    Thanks a lot for your response.
    I was considering doing what you just said. But then I deceided against it as I was not sure what would be the performance of this calll
    return (String[])list.toArray(new String[list.size()]);
    supposing I have a Method
    public Photo[] getPhotos()
    return (Photo[])list.toArray(new Photo[list.size()]);
    Everytime a getPhotos is called I would construct a new Array object . Wouldnt this be a performance killer.
    Thanks
    Niraj
    Well, not sure why, cuz it would seem like something
    it should handle. It already will make a new array if
    the given array isn't long enough, so it could check
    for null. But it doesn't. Anyway, the method would
    have to create an array at least as long anyway, so
    it's not like you'd save on memory or anything. The
    easiest thing is just to do this:
    return (String[])list.toArray(new
    String[list.size()]);

  • Adivce on implementing boolean equals(Object)

    Given that SomeClass extends Object and is is not part of an overly complicated hierarchy where each subclass adds some data useful to identify its instances.
    Which version is better and why?
    public boolean equals(Object o){
        return (o != null
            && this.id != null
            && this.getClass().equals(o.getClass())
            && this.id.equals(((SomeClass) o).id))
        || super.equals();
    public boolean equals(Object o){
        return (o != null
            && this.id != null
            && o instanceof SomeClass
            && this.id.equals(((SomeClass) o).id))
        || super.equals();
    }

    So your question is about instanceof vs. comparing the results of getClass, right?
    It depends on the semantics of your hierarchy.
    The contract of equals says it has to be symmetric. a.equals(b) must return the same result as b.equals(a).
    class Super {
    class Sub extends Super {
    Super super = new Super();
    Sub sub = new Sub();
    boolean b1 = super.equals(sub);
    boolean b2 = sub.equals(super); If you use instanceof, then super's equals must be final, or else Sub's equals must only check for instance of Super, not instanceof Sub. If Super checks for instanceof Super, and Sub checks for instanceof Sub, then b1 (super.equals(sub)) can be true (since sub is an instance of Super) but b2 (sub.equals(super)) can never be true.
    If you look at the collections hierarchy, you'll see that the equals methods check for instanceof the interface. For instance (HA!), two Lists are equal iff they both implement List, and they have the same elements in the same order. So ArrayList, LinkedList, and any custom List that you might implement must check instanceof List, not instanceof ArrayList, etc.
    The general rule is, if you're going to use instanceof, then to preserve symmetry, all classes in the subtree must check for instanceof the same class (or interface), and it has to be at the highest (closest to Object) level in the subtree of classes that could be equal to each other.
    Does that make sense?
    &para;

  • How to implement array of objects or vector of objects?

    Hello, i am working on a javabean that is connecting to a database and executes an sql string. The javabean returns the records retrieved in a tabular format.
    Currently i can achieve the above requireement, but only through using a simple table-formatted string, this is not dynamic and a 2d array approach would not be dynamic either.
    I have read a little about using a dynamic approach, possiblya vector of objects, or array list of objects to solve the problem, but i don't really know how to start, could anybody help me??
    The code i have so far is:
    package webtech;
    import java.sql.*;
    public class questiona {
    /* Step 1) Initialize Variables*/
    String result = "";
    String query = "select id, name, url, thumb_url, keywords, category, author from mytable;";
    String url = "";
    String driver = "";
    String uname = "";
    String dpass = "";
    /*Step 2) Make a database connection*/
    private Connection dbconn = null;
    public questiona()
    try
    Class.forName(driver);
    dbconn = DriverManager.getConnection(url, uname, dpass);
    /*Create an SQL statement*/
    Statement statement = dbconn.createStatement();
    if (statement.execute(query))
    {/*Step 3) If we have a result lets loop through*/
    ResultSet results = statement.getResultSet();
    ResultSetMetaData metadata = results.getMetaData();
    /*Validate result. Note switch to while loop if we plan on multiple results from query*/
    if(results != null)
    /*Use results setmetadata object to determine the columns*/
    int li_columns = metadata.getColumnCount();
    result += " <tr>\n\r";
    result += " <td>" + metadata.getColumnLabel(1) + "</td>\n\r";
    result += " <td>" + metadata.getColumnLabel(2) + "</td>\n\r";
    result += " <td>" + metadata.getColumnLabel(3) + "</td>\n\r";
    result += " <td>" + metadata.getColumnLabel(4) + "</td>\n\r";
    result += " <td>" + metadata.getColumnLabel(5) + "</td>\n\r";
    result += " <td>" + metadata.getColumnLabel(6) + "</td>\n\r";
    result += " <td>" + metadata.getColumnLabel(7) + "</td>\n\r";
    result += " </tr>\n\r";
    /*loop throught the columns and append data to our table*/
    while(results.next())
    result += " <tr>\n\r";
    result += " <td>" + results.getObject(1).toString() +"</td>\n\r";
    result += " <td>" + results.getObject(2).toString() +"</td>\n\r";
    result += " <td>" + results.getObject(3).toString() +"</td>\n\r";
    result += " <td>" + results.getObject(4).toString() +"</td>\n\r";
    result += " <td>" + results.getObject(5).toString() +"</td>\n\r";
    result += " <td>" + results.getObject(6).toString() +"</td>\n\r";
    result += " <td>" + results.getObject(7).toString() +"</td>\n\r";
    result += " </tr>\n\r";
    catch (ClassNotFoundException e)
    {     result = "<tr><td> Error in database";
    result += " <br/>" + e.toString() + "</td></tr>";
    catch (SQLException e)
    {     result = "<tr><td> Error in SQL";
    result += " <br/>" + e.toString() + "</td></tr>";
    finally
    try {
    if (dbconn !=null)
    { dbconn.close();}
    catch (SQLException e)
    {   result  = " <tr><td> Error in closing connection.";
    result += " <br/>" + e.toString() + "</td></tr>";
    public String getResults() {
    return result;
    }

    Cross-post
    http://forum.java.sun.com/thread.jspa?threadID=604770

  • Method implementation using ABAP objects

    hi folks,
    I am impelementing a method using one of the parameters, which is a internal table taken as an import parameter.
    I am using the field symbols to <b>modify</b> the table data  but it is not working.
    method IF_EX_PT_ABS_ATT_COUNTRY~CALCULATE_COUNTRY.
    The method CALCULATE_COUNTRY has a parameter
    TIMES_PER_DAY Importing TYPE PTM_TIMES_PER_DAY.
    This is the table tha t retrieves the data for the Absence infotype 2001 for an employee and has the field
    ABRST value populated.
    I need to clear the value for this field and update the table 'TIMES_PER_DAY' before it populates the infotype record.
    Hence I am writing the code in its method by calling the parameter.
    here is the piece of code....
    FIELD-SYMBOLS: <F1> TYPE PTM_TIMES_PER_DAY.
    loop at times_per_day into <F1> where datum eq begda.
       clear <F1>-abrst.
       ASSIGN <F1> to times_per_day.  ****ERROR
    endloop.
    endmethod.
    I know the error is because trying to assign the <F1> field symbol to internal table.
    But how can I do that ultimately I need to update the internal table 'times_per_day '
    ALSO TRIED THIS....
    data: w_tab type PTM_TIMES_PER_DAY.
    loop at times_per_day into w_tab where datum eq begda.
       CLEAR w_tab-abrst.
       modify times_per_day from w_tab transporting abrst.
    endloop.
    It gave an error saying the table 'times_per_day' cannot  be changed.
    I hope you got what I am trying to achieve here... any leads or guidelines will be really helpful,
    Thanks
    Vinu

    Is this table part of the IMPORT PARAMETERS  list. If that is the case you cannot change the table.
    It should be in the EXPORTING parametes to change.
    Regards,
    Ravi
    Note : Please mark all the helpful answers

  • Where is the getString() implementation for RS and Object class question

    Dear all,
    I had these two questions ringing since a long time.
    1)ResultSet is an interface.
    In my jdbc code I have generally written rs.getString() and rs.getInt etc.. without giving a second thought as to where exactly is this getter implemented !
    I have RTF API .. without too much help.
    Could some one kindly explain Where is the implementation of the getString method ?
    2) Could you please tell why the Wait() Notify() and NotifyAll methods have been implemented in the Object class ? What was the need to define em in the Object class ?
    Thanks in advance for your time spent on this.
    Rgds

    Sarvananda wrote:
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    Rgds
    >
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    A desire to not have to couple your code to a particular database and JDBC driver. It's a classic example of the abstract factory pattern

Maybe you are looking for

  • ITunes doesn't understand Uninstall - please help

    Seems that itunes wants to be in the system eternally. itunesmobiledevice service needs to die a horrible death how do I remove it? Where do I log a BUG on the uninstaller?

  • Referncing document should not be changed

    Dear SAP Gurus, I have a scenario and it is for example that if sales order is created with reference to the quotation so quotation should not be changed....and the sales order should have the same material which is copied from the quotation and we s

  • Can I rollover an image to "remove" it to have clickable links show up once at hidden state?

    I have a design wherein I want certain elements to change states on rollover. With this action, there would be a line of text with each one clickable to a different link. Right now I cannot find a good way to have one image "hide" on rollover, reveal

  • Transferring songs from an iPod Mini

    I have an iPod mini and used to have a PC. I recently bought a MacBook, and now have iTunes 8 on my MacBook. How do I transfer to the songs from my iPod mini and transfer them to my MacBook into iTunes?

  • Build Problems DBXML-2.4.16 And RHEL 5.3 : __ctype_b Error.

    Hello, I'm attempting a new install of dbxml 2.4.16 on a RHEL 5.3 system. Using the buildall.sh, I am able to build DBXML and Xerces, however, XQilla fails with this error: gmake[1]: Entering directory `/home/b/dbxml/dbxml-2.4.16/xqilla/build' /bin/s