How to cast this?

Hi Folks!
I am new in java and trying to cast a long in integer. I am not sure what?s wrong in my code?
Can anybody tell me what?s wrong and how should I get it correct?
Here is my code.
  Integer a1,b1;
  Stack st = new Stack();
    a1 = (Integer)st.pop();
    b1 = (Integer)st.pop();
    long x;
    x=(long)a1;
    sdos.writeLong(x);
    dos.flush();Thanks a lot in Advance.

x = a1.longValue();http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#longValue()

Similar Messages

  • How to cast ArrayList to ....

    Hi,
    I got an ArrayList and its values are (1,2,3)
    List tempList = new ArrayList();
    tempList.add("1");
    tempList.add("2");
    tempList.add("3");
    I am wondering how to convert it to an int [] array.
    int [] tempInt;
    I know that I can do this : tempList.toArray
    but I don't know how to cast this to int[] type of array
    (note: not integet [] , just int[])
    Can anyone help? thanks a lot.

    Note: It would be much more efficient to use the wrapper classes for storing primitives in a Vector/ArrayList/LinkedList/... :
    tempList.add(new Integer(1));
    tempList.add(new Integer(2));
    tempList.add(new Integer(3));
    (getting the array as an int[] still requires a for-loop)

  • How to cast vector to vector with out using loop. and how to override "operator =" of vector for this kind of condition.

    Hi All How to TypeCast in vector<>...  typedef  struct ...  to class... 
    //how to cast the vector to vector cast with out using loop
    // is there any way?
    //================ This is Type Definition for the class of ClsMytype=====================
    typedef struct tagClsMytype
    CString m_Name;
    int m_Index;
    double m_Value;
    } xClsMytype;
    //================ End of Type Definition for the class of ClsMytype=====================
    class ClsMytype : public CObject
    public:
    ClsMytype(); // Constructor
    virtual ~ClsMytype(); // Distructor
    ClsMytype(const ClsMytype &e);//Copy Constructor
    // =========================================
    DECLARE_SERIAL(ClsMytype)
    virtual void Serialize(CArchive& ar); /// Serialize
    ClsMytype& operator=( const ClsMytype &e); //= operator for class
    xClsMytype GetType(); // return the typedef struct of an object
    ClsMytype& operator=( const xClsMytype &e);// = operator to use typedef struct
    ClsMytype* operator->() { return this;};
    operator ClsMytype*() { return this; };
    //public veriable decleare
    public:
    CString m_Name;
    int m_Index;
    double m_Value;
    typedef struct tagClsMyTypeCollection
    vector <xClsMytype> m_t_Col;
    } xClsMyTypeCollection;
    class ClsMyTypeCollection : public CObject
    public:
    ClsMyTypeCollection(); // Constructor
    virtual ~ClsMyTypeCollection(); // Distructor
    ClsMyTypeCollection(const ClsMyTypeCollection &e);//Copy Constructor
    DECLARE_SERIAL(ClsMyTypeCollection)
    virtual void Serialize(CArchive& ar);
    xClsMyTypeCollection GetType();
    ClsMyTypeCollection& operator=( const xClsMyTypeCollection &e);
    ClsMyTypeCollection& operator=( const ClsMyTypeCollection &e); //= operator for class
    void Init(); // init all object
    CString ToString(); // to convert value to string for the display or message proposed
    ClsMyTypeCollection* operator->() { return this;}; // operator pointer to ->
    operator ClsMyTypeCollection*() {return this;};
    public:
    vector <ClsMytype> m_t_Col;
    //private veriable decleare
    private:
    //===================================================
    ClsMytype& ClsMytype::operator=( const xClsMytype &e )
    this->m_Name= e.m_Name;
    this->m_Index= e.m_Index;
    this->m_Value= e.m_Value;
    return (*this);
    //==========================Problem for the vector to vector cast
    ClsMyTypeCollection& ClsMyTypeCollection::operator=( const xClsMyTypeCollection &e )
    this->m_t_Col= (vector<ClsMytype>)e.m_t_Col; // how to cast
    return (*this);
    Thanks in Advance

    Hi Smirt
    You could do:
    ClsMyTypeCollection* operator->() {
    returnthis;};
    // operator pointer to ->
    operatorClsMyTypeCollection*()
    {returnthis;};
    public:
    vector<ClsMytype>
    m_t_Col;//??
    The last line with "vector<xClsMytype>
    m_t_Col;". It compiles but I doubt that is what you want.
    Regards
    Chong

  • How to cast an object to a class known only at runtime

    I have a HashMap with key as a class name and value as the instance of that class. When I do a 'get' on it with the class name as the key, what I get back is a generic java.lang.Object. I want to cast this generic object to the class to which it belongs. But I don't know the class at compile time. It would be available only at runtime. And I need to invoke methods on the instance of this specifc class.
    I'm not aware of the ways to do it. Could anybody suggest/guide me how to do it? I would really appreciate.
    Thanks a lot in advance.

    Thanks all for the prompt replies. I am using
    reflection and so a generic object is fine, I guess.
    But a general question (curiosity) specific to your
    comment - extraordinarily generic...
    I understand there's definitely some overhead of
    reflection. So is it advisable to go for interface
    instead of reflection?
    Thanks.Arguments for interfaces rather than reflection...
    Major benefit at run-time:
    Invoking a method using reflection takes more than 20 times as long without using a JIT compiler (using the -Xint option of Java 1.3.0 on WinNT)... Unable to tell with the JIT compiler, since the method used for testing was simple enough to inline - which resulted in an unrealistic 100x speed difference.
    The above tests do not include the overhead of exception handling, nor for locating the method to be executed - ie, in both the simple method invocation and reflective method invocations, the exact method was known at compile time and so there is no "locative" logic in these timings.
    Major benefit at compile-time:
    Compile-time type safety! If you are looking for a method doSomething, and you typo it to doSoemthing, if you are using direct method invocation this will be identified at compile time. If you are using reflection, it will compile successfully and throw a MethodNotFoundException at run time.
    Similarly, direct method invocation offers compile-time checking of arguments, result types and expected exceptions, which all need to be dealt with at runtime if using reflection.
    Personal and professional recommendation:
    If there is any common theme to the objects you're storing in your hashtable, wrap that into an interface that defines a clear way to access expected functionality. This leaves implementations of the interface (The objects you will store in the hashtable) to map the interface methods to the required functionality implementation, in whatever manner they deem appropriate (Hopefully efficiently :-)
    If this is feasible, you will find it will produce a result that performs better and is more maintainable. If the interface is designed well, it should also be just as extensible as if you used reflection.

  • How to cast an Object into a specific type (Integer/String) at runtime

    Problem:
    How to cast an Object into a specific type (Integer/String) at runtime, where type is not known at compile time.
    Example:
    public class TestCode {
         public static Object func1()
    Integer i = new Integer(10); //or String str = new String("abc");
    Object temp= i; //or Object temp= str;
    return temp;
         public static void func2(Integer param1)
              //Performing some stuff
         public static void main(String args[])
         Object obj = func1();
    //cast obj into Integer at run time
         func2(Integer);
    Description:
    In example, func1() will be called first which will return an object. Returned object refer to an Integer object or an String object. Now at run time, I want to cast this object to the class its referring to (Integer or String).
    For e.g., if returned object is referring to Integer then cast that object into Integer and call func2() by passing Integer object.

    GDS123 wrote:
    Problem:
    How to cast an Object into a specific type (Integer/String) at runtime, where type is not known at compile time.
    There is only one way to have an object of an unknown type at compile time. That is to create the object's class at runtime using a classloader. Typically a URLClassloader.
    Look into
    Class.ForName(String)

  • Colorsync Utility. Whenever I click on Devices or Filters, it hangs and I have to force quit. Any ideas as to how to fix this?

    I'm having an issue with Colorsync Utility. When I open the utility I can access Profile First Aid, Profiles and the Calculator but whenever I click on Devices or Filters, it hangs and I have to force quit. I recently re-profiled my NEC monitor using xRite i1Profiler Pro and saved the ICC profile as "version 4". When I went to use the Nik's ColorEfex Pro 4 plug-in, in Adobe Photodhop CS5.1 (Creative Suite 5.5), I got a cyan cast across all my images. Nik said it had to do with a corrupt ICC profile but when I ran Profile First Aid, the only profile that came up as needing repair ( and couldn't) was EW-sRGB. I reprofiled the monitor only this time I saved it as "version 2", and the plug-in worked fine. What surprises me is that Colorsync Utilty always used to work without issue, and I never seemed to have a problem creatinga and saving ICC profiles using version 4. Any ideas as to what is causing this problem and  how to fix this?
    Thanks.
    James

    I updated my software, and deleted my history/cache.  Also, when I try to use Preview, it says that it was forced to quit while restoring windows, so when I click restore windows nothing happens.  I can't view anything either.  The only thing I can think that may have caused these problems is I tried to shut down and had to force it to by holding the power button.  I rarely shut it off.

  • How to cast in ABAP ?

    Hi,
    I need to cast a data but i don't kow how to do it in ABAP.
    Actually, I have a variable typed QUAN (quantity i guess) and i want to concatenate it in a String variable. That's not possible.
    The solution i've found is to move the Quan variable to a temporary String variable. I think that's a kind of implicit casting.
    Then, including this temporary string variable in the Concatenate instruction is possible.
    My question is :
    Can I directly cast this data instead of using a temporary variable ?
    In Java or VB.NET langauges, we can cast variable like that
    (String)my_variable
    How to do it in ABAP ?
    Thanks

    hi,
    You got to use the temporary variable of char type as shown below.
    data : v_quant type netpr value '1000.00',
             v_char(10).
    move v_qunat to v_char.
    Regards,
    Santosh

  • Function returning a set of records - how to do this?

    Hi,
    I need to return something of a table as a result:
    function Find_Item (vNUMBER in NUMBER(3,0)
    vNAME in VARCHAR2(200) ) return ???
    as
    begin
    SELECT UUID, Number, Name FROM Tab1
    Where NUMBER LIKE vNUMBER|| '%'
    intersect
    SELECT UUID, Number, Name FROM Tab1
    Where NAME LIKE vNAME|| '%' ;
    end;
    How to do this? Should I use a collection? Any ideas? I would be grateful for any hint.
    Best regards,
    Alicja

    user651039 wrote:
    And it would work if not for INTERSECT. So, I either I change the query or have to find walk-around.What is the issue with the INTERSECT? Why should the approach shown not work when using INTERSECT?
    Note that you can't define the parameters of your function like that, you have to specify the length of the varchar2 column in the calling code.
    If your query is going to return potentially a large number of rows you should consider using a "pipelined" function, as already mentioned, as the non-pipelined version could be consuming a lot of memory in case a large collection is going to be generated.
    Here's a sample of a pipelined table function:
    alter session set nls_language = 'AMERICAN';
    set echo on linesize 130 feedback 1
    drop type t_find_item_record_col force;
    drop type t_find_item_record force;
    drop function find_item;
    create or replace type t_find_item_record as object(
    uuid varchar2(30),
    a_number number,
    a_name varchar2(30)
    create or replace type t_find_item_record_col as table of t_find_item_record;
    create or replace function find_item(
    vNUMBER in NUMBER, vNAME in VARCHAR2) return t_find_item_record_col pipelined
    as
      a_find_item_record_col t_find_item_record_col;
      cursor c is
      select t_find_item_record(uuid, a_number, a_name) from (
      SELECT cast('a' as varchar2(30)) as UUID, 1 as a_Number, cast('b' as varchar2(30)) as a_Name
      FROM dual
      Where 35 LIKE vNUMBER|| '%'
      intersect
      SELECT 'a' as UUID, 1 as a_Number, 'b' a_Name FROM dual
      Where 'Bob' LIKE vNAME|| '%'
    begin
      open c;
      loop
        fetch c bulk collect into a_find_item_record_col limit 100;
        for i in 1..a_find_item_record_col.count loop
          pipe row(a_find_item_record_col(i));
        end loop;
        exit when a_find_item_record_col.count = 0;
      end loop;
      close c;
      return;
    end;
    select * from table(find_item(35, 'Bob'));Another option you might want to consider is using a REF CURSOR return type, so that you open the cursor accordingly in your function and return the opened cursor to the caller. The caller can then fetch from this cursor.
    And here's a sample function using ref cursor:
    create or replace function find_item_cursor(
    vNUMBER in NUMBER, vNAME in VARCHAR2) return sys_refcursor
    as
      c sys_refcursor;
    begin
      open c for
      SELECT cast('a' as varchar2(30)) as UUID, 1 as a_Number, cast('b' as varchar2(30)) as a_Name
      FROM dual
      Where 35 LIKE vNUMBER|| '%'
      intersect
      SELECT 'a' as UUID, 1 as a_Number, 'b' a_Name FROM dual
      Where 'Bob' LIKE vNAME|| '%';
      return c;
    end;
    variable a refcursor
    exec :a := find_item_cursor(35, 'Bob')
    print aHere's the output of the samples:
    Session altered.
    SQL>
    SQL> drop type t_find_item_record_col force;
    Type dropped.
    SQL>
    SQL> drop type t_find_item_record force;
    Type dropped.
    SQL>
    SQL> drop function find_item;
    Function dropped.
    SQL>
    SQL> create or replace type t_find_item_record as object(
      2  uuid varchar2(30),
      3  a_number number,
      4  a_name varchar2(30)
      5  );
      6  /
    Type created.
    SQL>
    SQL> create or replace type t_find_item_record_col as table of t_find_item_recor
    d;
      2  /
    Type created.
    SQL>
    SQL>
    SQL> create or replace function find_item(
      2  vNUMBER in NUMBER, vNAME in VARCHAR2) return t_find_item_record_col pipelin
    ed
      3  as
      4    a_find_item_record_col t_find_item_record_col;
      5    cursor c is
      6    select t_find_item_record(uuid, a_number, a_name) from (
      7    SELECT cast('a' as varchar2(30)) as UUID, 1 as a_Number, cast('b' as varc
    har2(30)) as a_Name
      8    FROM dual
      9    Where 35 LIKE vNUMBER|| '%'
    10    intersect
    11    SELECT 'a' as UUID, 1 as a_Number, 'b' a_Name FROM dual
    12    Where 'Bob' LIKE vNAME|| '%'
    13    );
    14  begin
    15    open c;
    16    loop
    17      fetch c bulk collect into a_find_item_record_col limit 100;
    18      for i in 1..a_find_item_record_col.count loop
    19        pipe row(a_find_item_record_col(i));
    20      end loop;
    21      exit when a_find_item_record_col.count = 0;
    22    end loop;
    23    close c;
    24    return;
    25  end;
    26  /
    Function created.
    SQL>
    SQL> select * from table(find_item(35, 'Bob'));
    UUID                             A_NUMBER A_NAME
    a                                       1 b
    1 row selected.
    SQL>
    SQL> create or replace function find_item_cursor(
      2  vNUMBER in NUMBER, vNAME in VARCHAR2) return sys_refcursor
      3  as
      4    c sys_refcursor;
      5  begin
      6    open c for
      7    SELECT cast('a' as varchar2(30)) as UUID, 1 as a_Number, cast('b' as varc
    har2(30)) as a_Name
      8    FROM dual
      9    Where 35 LIKE vNUMBER|| '%'
    10    intersect
    11    SELECT 'a' as UUID, 1 as a_Number, 'b' a_Name FROM dual
    12    Where 'Bob' LIKE vNAME|| '%';
    13    return c;
    14  end;
    15  /
    Function created.
    SQL>
    SQL> variable a refcursor
    SQL>
    SQL> exec :a := find_item_cursor(35, 'Bob')
    PL/SQL procedure successfully completed.
    SQL>
    SQL> print a
    UUID                             A_NUMBER A_NAME
    a                                       1 b
    1 row selected.Regards,
    Randolf
    Oracle related stuff:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle:
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • When I start the Mozilla Firefox I get error message "ReferenceError: Globalstorage is not defined." How to solve this problem?

    When I start the Mozilla Firefox I get error message "ReferenceError: Globalstorage is not defined." How to solve this problem?
    -Vinayak

    Disabling Samsung Caster add-on solved this issue for me.

  • HOW TO  CAST NVARCHAR2 TO BLOB

    Hello
    i must stock my data to a nvarchar2 data (unicode) and i must also make full text search on this column, oracle does not support full text search on unicode data, so i have decided to stock my unicode data to a blob clomun, after i can create a full text index and search data.
    my problem is how to cast nvarchar2 to blob in oracle. i'm using a vb program with adodb to write and read data from the db and i must write the data (unicode text) in the blob column using the right cast which allows me to use directly adodb to read information (i have tried this with sql server with a varbinary(max) column and it works : i write a nvarchar data to the verbinary(max) column using the cast function, after, adodb can read directly the information without any explicit cast) is this possible on oracle
    thank you for your help

    What is your database character set? If it's AL32UTF8 you shouldn't really need to use NVARCHAR2 at all - you can store Unicode data in a VARCHAR2 or CLOB column.
    BLOB doesn't seem like the right datatype to use - if it's text you want to index then it should be in a VARCHAR2 or a CLOB column. If you put it in a BLOB then you'll have to explicity tell Oracle not to treat it as a binary document, and you will have to handle all character set issues manually.
    I'm afraid I know nothing about VB or ADODB.

  • How to cast presentation variable

    Hi,
    How to cast the presentation variable in answers
    Thanks in advance
    naresh

    Hi Naresh,
    Have you tried to use the CAST function?
    CAST(@{test}{123} as char)
    With the above column Formula in Answers Request I can able to view the result 123, which is the default value specified the presentation variable 'test'.
    Hope this will helps you..
    -Vency

  • How to cast a BLOB to OrdImage

    Hi,
    How can I cast or convert a BLOB to OrdImage? For example,
    <import...>
    public class ConvertBlobToOrdImage {
    public static void main(String args[]) throws Exception {
    // Load the Oracle JDBC driver:
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    // Connect to the database:
    Connection conn =
    DriverManager.getConnection(<"Your database connection">);
    conn.setAutoCommit(false);
    // Create a Statement:
    Statement stmt = conn.createStatement();
    String query = "SELECT blob FROM image_t where image_id = 1";
    OracleResultSet rset = (OracleResultSet) stmt.executeQuery(query);
    rset.next();
    OrdImage imageProxy = (OrdImage) rset.getCustomDatum(1, OrdImage.getFactory()); // <-- java.lang.ClassCastException: oracle.sql.BLOB
    rset.close();
    int height = imageProxy.getHeight();
    int width = imageProxy.getWidth();
    System.out.println("Image Dimension: " + height + " x " + width);
    System.out.println("Image Mime Type: " + imageProxy.getMimeType());
    TIA,
    Henry

    xwindy wrote:
    Does anyone knows how to cast a HashMap to HashMap<String, Object>?
    the session.getAttribute return only a HashMapthere is no way to do this safely
    you can use this annotation to suppress unchecked warnings
    @SuppressWarnings("unchecked")

  • Just for fun:  Can you guess how I did this?

    A few months ago a thread here discussed different way to stroke 3D objects in After Effects.  There were lots of clever suggestions.
    I made a TV spot last week that uses growing 3D ribbons to spell out the 2012 in the product title.  There are straight planes and curves within the ribbon paths, and lighting and shadows were required to match the original album art it replicates.  I needed to get the job done quickly and didn't have time to use a 3D application, so I used (what I think) was a rather innovative approach.
    So, for a bit of fun, can you pick how I did this?  The project is created entirely in AE, in one composition. 
    Apologies for the heavy compression in the video.

    Thanks Todd!
    My first attempt was exactly Rick's, using stacked solids with Stroke applied.  I gave up on it because, once shadows were applied, the "ribbons" seemed to develop a mottled texture, presumeably because each layer in the stack casts a shadow on the layer behind it.  Using Rick's design above, here's an example:
    So in the end, I used text layers!  Each ribbon is simply a long string of Helvetica "I" characters, with their kerning pulled back so all the characters touch.  Convert to per-character 3D, rotate X axis 90 degrees, and apply mask as text path.  Then I use a simple Text Animator on opacity to draw the lines on or off. 
    The great advantage of this is no cumbersome stack of layers.  Each colour is one layer, so there's just five layers in my comp for each object. The "20" is one object, then the "1", then the "2" - 15 layers in all for the whole thing.  Changing colours is as easy as changing a single text layer.
    A total render hog, all the same:  it took 11 hours to render the 15 second spot, on an 8 core Mac Pro with 16GB of RAM.  But in 3D Draft mode the comp was surprisingly easy to work with.  It's just the lighting and shadows that slow things down.
    Anyways, perhaps this may inspire someone else to do something interesting with text layers. 

  • How to cast an array object to array of string

    * Can someone please tell me why SECTION 3 causes a cast
    * exception?
    * What I am really trying to do is put Strings into a vector and
    * return them as an array of String with a line like:
    *     return (String[])myVector.toArray();
    * How to do this?
    * Thank You!
    public class CastArrayTest
         public static void main(String args[]){
              //SECTION 1: This works
              String[] fruits = {"apple", "banana"};
              Object[] objs = (Object[])fruits;
              String[] foods = (String[])objs;
              for (int i = 0 ; i < foods.length ; i++){
                   System.out.println(foods);
              //SECTION 2: this works too
              Object anObj = new Object();
              String aString = "ok";
              anObj = aString;
              String anotherString = (String)anObj;
              System.out.println("word for single obj is " + anotherString);
              //SECTION 3: this causes cast exception at line
              // String[] strings = (String[])stuff
              Object[] stuff = new Object[2];
              String a = "try";
              String b = "this";
              stuff[0] = a;
              stuff[1] = b;
              String[] strings = (String[])stuff;
              for (int x = 0 ; x < strings.length ; x++){
                   String s = strings[x];
                   System.out.println("the string is " + strings[x]);

    I understand all replies so far, but from my
    understanding, objects are passed by reference No, they're not. Rather, object references are passed by value.
    Object obj = new Object();
    String a = "pass me by reference";
    Object anotherObj = (Object)a; // this explicit cast is not necessary
    String anotherString = (String)anotherObj; // this cast works because the object in question is a String
    There's no passing in that code, so I'm not sure where that even came from. However, that works because it's all legal casting.
    works as I think it should, and does, and futhermore
    String[] cast to Obj[] cast to String[] works also...Because the object you're casting actually is a String[].
    so why not if Obj[] to String[] Because String[] is not a subclass of Object[]. That's just how the language is specified.
    futhermore if they are
    all string...Again, this has no bearing on the type of the array object.
    I saw hot to cast array to String[] and wondered if
    this is real cast or calls the toString method...It's a real cast.
    but most importantly, does this mean if I have a
    vector of Strings and want to get them as an array of
    strings, I have to loop through the Obj[] (or vector)
    and cast each to (String)...just to get them as an
    array of String[]....No, zparticle's code can do that.

  • Hql how to cast number to varchar2

    Hello.
    How to cast number to varchar2(to string)? I'm using hql toplink implementation and (don't know why) functions like cast(... as ...), to_char(...) and str(...) don't work. Please help me.
    Kuba :).
    Edited by: 854998 on 2011-04-27 03:12

    Hello Chris.
    First of all I'd like to thank you for answer. :)
    1)I can't use native query.
    2)What do you mean?
    3)I can't upgrade.
    I have something like this(it's only simple example, I have more complex query):
    getManager().createQuery("SELECT obj FROM " + EntityClass.class.getSimpleName() + " obj "
                        + " WHERE '14' = obj.number").getResultList();
    r.number is Number in Oracle and Long in entity class.
    I want to cast obj.number to String.
    Here: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-expressions expressions like cast is valid.
    So, where's the problem? My toplink version is too old?
    Thanks a lot
    Kuba.

Maybe you are looking for