How to cast an int into an Object?

If I want to push the int called result (e.g. result = 3 + 4) on my Stack, it doesn't work, because push asks for an Object.
So how can I cast my int into an Object?
Thanks for help!
trampoline

All the primitive types have wrapper classes. In this case use the following:
int result = 3+4;
Integer iResult = new Integer(result);
Now push iResult onto your stack.

Similar Messages

  • How to format an int into something of this nature 12,000

    Does any one know how to format an int into a specifically formatted String?
    let say:
    int i = 12000
    I want:
    Sting s = $ 12,000
    Thanks for your help!!

    Yes, you use a DecimalFormat object. It's in the java.text package, and the API documentation has a lot of information about how to use it.

  • How to convert Property files into Java Objects.. help needed asap....

    Hi..
    I am currently working on Internationalization. I have created property files for the textual content and using PropertyResourceBundles. Now I want to use ListResourceBundles. So what I want to know is..
    How to convert Property files into Java Objects.. I think Orielly(in their book on Internationalization) has given an utitlity for doing this. But I did not get a chance to look into that. If anyone has come across this same issue, can you please help me and send the code sample on how to do this..
    TIA,
    CK

    Hi Mlk...
    Thanks for all your help and suggestions. I am currently working on a Utility Class that has to convert a properties file into an Object[][].
    This will be used in ListResourceBundle.
    wtfamidoing<i>[0] = currentKey ;
    wtfamidoing<i>[1] = currentValue ;I am getting a compilation error at these lines..(Syntax error)
    If you can help me.. I really appreciate that..
    TIA,
    CK

  • How to read a binaryfile into an object

    Hello,
    I want to read a binary file into an object. In this object, we have
    several variables which need to be filled. I did the following thing:
    ---Start code---
    import java.io.*;
    import java.lang.reflect.*;
    public class BinaryFile {
      private File file;
      private DataInputStream dis;
      public BinaryFile() {}
      // Open the file
    public void openFile(String file) throws FileNotFoundException {
        this.file = new File(file);
        if (! this.file.exists())
          throw new FileNotFoundException();
        dis = new DataInputStream(new FileInputStream(this.file));
      // Close the file
      public void closeFile() throws IOException {
        dis.close();
    public void readObject(int offset, Object o) throws EndOfFileException,
                           IOException {
        // Get the fields in the object
        Field[] fields = o.getClass().getFields();
        try {
          String type, naam;
          Class className;
          int lengte, arrayLengte;
          boolean isArray;
          for (int i = 0; i !< fields.length; i++) {
            naam = fields.getName(); // Get the name of the field
    className = fields[i].getType(); // Get the type
    type = className.getName(); // Get the name of the type
    isArray = className.isArray(); // Is it an array?
    arrayLengte = 1;
    fields[i].setAccessible(true); // For setting the values
    if (isArray) {                      // If it is an array,
    type = getType(type); // decode it
    // Get the size of the array
    arrayLengte = Array.getLength(fields[i].get(o));
    // Determine the type of the variable and fill it.
    // Char
    if (type.equalsIgnoreCase("char")) {
    lengte = 1;
    if (isArray)
    fields[i].set(o, readChars(arrayLengte * lengte));
    else
    fields[i].setChar(o, readChar());
    // Byte
    } else if (type.equalsIgnoreCase("byte")) {
    lengte = 1;
    if (isArray)
    fields[i].set(o, readBytes(arrayLengte * lengte));
    else
    fields[i].setByte(o, readByte());
    // Short
    } else if (type.equalsIgnoreCase("short")) {
    lengte = 2;
    if (isArray)
    fields[i].set(o, readShorts(arrayLengte * lengte));
    else
    fields[i].setShort(o, readShort());
    // Int
    } else if (type.equalsIgnoreCase("int")) {
    lengte = 4;
    if (isArray)
    fields[i].set(o, readInts(arrayLengte * lengte));
    else
    fields[i].setInt(o, readInt());
    // Float
    } else if (type.equalsIgnoreCase("float")) {
    lengte = 4;
    if (isArray)
    fields[i].set(o, readFloats(arrayLengte * lengte));
    else
    fields[i].setFloat(o, readFloat());
    // Long
    } else if (type.equalsIgnoreCase("long")) {
    lengte = 8;
    if (isArray)
    fields[i].set(o, readLongs(arrayLengte * lengte));
    else
    fields[i].setLong(o, readLong());
    // Double
    } else if (type.equalsIgnoreCase("double")) {
    lengte = 8;
    if (isArray)
    fields[i].set(o, readDoubles(arrayLengte * lengte));
    else
    fields[i].setDouble(o, readDouble());
    catch (IOException ioex) {
    throw ioex;
    catch (Exception ex) {
    ex.printStackTrace();
    // Methods for reading from the DataInputStream
    private char[] readChars(int lengte) throws IOException {
    char[] c = new char[lengte];
    for (int i = 0; i < c.length; i++)
    c[i] = dis.readChar();
    return c;
    private char readChar() throws IOException {
    return dis.readChar();
    private byte[] readBytes(int lengte) throws IOException {
    byte[] b = new byte[lengte];
    for (int i = 0; i < b.length; i++)
    b[i] = dis.readByte();
    return b;
    private byte readByte() throws IOException {
    return dis.readByte();
    private short[] readShorts(int lengte) throws IOException {
    short[] s = new short[lengte];
    for (int i = 0; i < s.length; i++)
    s[i] = dis.readShort();
    return s;
    private short readShort() throws IOException {
    return dis.readShort();
    private int[] readInts(int lengte) throws IOException {
    int[] i = new int[lengte];
    for (int j = 0; j < i.length; j++)
    i[j] = dis.readInt();
    return i;
    private int readInt() throws IOException {
    return dis.readInt();
    private double[] readDoubles(int lengte) throws IOException {
    double[] d = new double[lengte];
    for (int i = 0; i < d.length; i++)
    d[i] = dis.readDouble();
    return d;
    private double readDouble() throws IOException {
    return dis.readDouble();
    private float[] readFloats(int lengte) throws IOException {
    float[] f = new float[lengte];
    for (int i = 0; i < f.length; i++)
    f[i] = dis.readFloat();
    return f;
    private float readFloat() throws IOException {
    return dis.readFloat();
    private long[] readLongs(int lengte) throws IOException {
    long[] l = new long[lengte];
    for (int i = 0; i < l.length; i++)
    l[i] = dis.readLong();
    return l;
    private long readLong() throws IOException {
    return dis.readLong();
    // If it is an array, decode it. The type will be "[x" where x is
      // translated according to the table
      private String getType(String type) {
              BaseType Character  Type  Interpretation
              B  byte  signed byte
              C  char  Unicode character
              D  double  double-precision floating-point value
              F  float  single-precision floating-point value
              I  int  integer
              J  long  long integer
              L<classname>;  reference  an instance of class <classname>
              S  short  signed short
              Z  boolean  true or false
              [  reference  one array dimension
        int arrayIndex = type.indexOf("[");
        if (arrayIndex != type.lastIndexOf("[")) {
          System.out.println("Multiple arrays not supported!");
          return type;
    char tempType = type.charAt(arrayIndex + 1);
    switch (tempType) {
    case 'B':
    type = "byte";
    break;
    case 'C':
    type = "char";
    break;
    case 'D':
    type = "double";
    break;
    case 'F':
    type = "float";
    break;
    case 'I':
    type = "int";
    break;
    case 'J':
    type = "long";
    break;
    case 'S':
    type = "short";
    break;
    default:
    System.out.println("Couldn't define this type: " + type);
    type = type;
    break;
    return type;
    ---End code---
    Now the problem. I want to read the header of an executable. I turn to
    the file format as described in WINNT.H. If it is a char, it will read
    ok. For everything else, it doesn't work. A WORD (= short in java) for
    instance, doesn't come up with the real value.
    The purpose of this piece of code is to emulate the structs that are
    used in C.
    What is the problem here and what is the solution?

    before coding a long class, look at Serialization mechanism in java
    maybe (or maybe not) it should be a better soution ...

  • How to convert a string into an objects name?

    Hi
    I have the following problem;
    I have a string
    String a = "e1"
    and a method
    call(Event e1) that calls the "Event" class with object the name of the string a.
    How can I convert the strings name into an object so as to use it in the "call" method?
    Any ideas?
    Thanks in advance

    I don't know if this helps you, but you can do things like this.
    String a = "com.example.SomeEvent";
    //Instantiate com.example.SomeEvent
    Object o = Class.forName(a).newInstance();SomeEvent must have a non-argument constructor for this to work.
    Class that will be instantiated depens on runtime value of String a, and can be different across different executions of the program.

  • How to extract Cognos Data into Business Objects?

    Hi All,
    I would like to know whether anyway to pull Cognos data into Business Objects?
    1. Pull data thru Universe from Cognos Cubes?
    2. Pull data using Crystal reports from Cognos Cubes?
    3. Or any otehr method of pulling data from Cognos Cubes?
    If nothing is possible I would have to explore using the RDBMS Tables to build Universe, WebI and then present in Xcelsius. Anybody is aware of getting data from Cognos?
    Thanks in advance.
    Alex.

    Cognos Reporting on SAP BI data
    We need to create a new project to import the structure of the SAP BI cube or Multiprovider.
    Enter User ID and password.
    Click on OK
    It will ask you to enter the User ID and password again. After enter the User ID and password it will ask you to select the language.
    Then it will ask you to select the metadata source, select the Data source as shown in below fig. and click next.
    Select the data Source as shown in below.
    Here we are planning to import SAP BW cube so we have to select SAP BW and click on next.
    Select sign on and Click on OK.
    Here we have to select our desired cube or multiprovider and click next.
    Now we have to select the language again.
    Here Cognos is giving the flexibility to use different options when importing cube structures.
    Here I am selecting to use the technical name of the objects and to bring same model as it is in SAP BI.
    Finally it will show list of all objects which are imported from SAP BI.
    When you click on finish it will take to the frame work manager. There you will see the SAP BI Cube Structure.
    Now it is exactly imported like SAP BW extended star schema model.
    Here you can compare the technical names of the dimensions in both in Cognos and SAP BI is same.
             COGNOS    Model                                         SAP BI Cube model         
    Here I am comparing the values of the info Objects with in one dimension.
                   Cognos Model                                                   SAP BI Model
    If there are any hierarchies in BI, it will form separately as shown in below fig.
    When you open the main object of Program definition, we will find 3 objects under this.
    It is always recommendable to use Level 01 objects.
    This is how it looks when you open all the above 3 objects. You can use any of those depends on your report requirement.
    When you open the info object if you see number of different items, that means this info object has got attributes in it.
    0COMP_CODE is the technical name of the info object in BI.
    In Cognos if it technical name starts with 1  Short Text of the Info Object.
                                                                       2  Key of the Info Object.
                                                                       4  Long Text of the Info Object.
                                                             5  Medium Text of the Info Object.
    LELEL00  Is Summarized values.
    LEVEL01  Is Item level values of Info Object.
    Once you see this in bw/bi environment, i hope you know how to gather and use it in BOBJ environment !!

  • How to place grouped items into another object with content collector tool?

    Is it possible to paste a group into another object (i.e. frame) by using the Content Collector Tool while linking the content?  Paste Into is either deselected or possibly whatever was last saved to the clipboard ends up inserting. I was able to place grouped, linked content into a frame (and later applied a scrollable frame overlay to it) once or twice but can't seem to repeat. Tried selecting the object being pasted into.. holding shift, holding ctrl, all kinds of options, just very confused now.

    Found a potential work-around (I think....).
    1. Use the Content Collector tool and select grouped objects
    2. Select Content Placer tool, check "Create Link"
    3. Place grouped object into doc/onto page with Content Placer tool
    4. Copy placed grouped objects
    5. Paste into frame that will be scrollable later
    For now it seems like the link still works

  • How to change Transport request into local object $temp.?

    Hi experts,
    I would like to know to how to change a Transport request into and local object.
    I have already assigned Infopackage to TR, but its not required. We dont want this infopackage to be transported to prod. So how can i change that as a local object.
    Please put our valuable inputs.
    Thanks in advance.
    Regards,
    Dubbu

    Go To that Infopackage ,
    Extras Menu----Object catalog entry.  There you can change package name.
    or
    In SE09---Under the transport requests you can search for the infopackage name and delete from the TR.
    Regards,
    Srikanth
    Edited by: srikanth on Feb 19, 2009 2:26 PM
    Edited by: srikanth on Feb 19, 2009 2:27 PM

  • How do I fill color into an object drawn with the brush tool?

    I'm watching a tutorial to learn more, and one think I still don't know is how to fill something with color that is drawn out via the brush tool. Say I draw a black circle and want to fill the color to green. I'm not talking about Live Paint were you select an object. I see in the tutorial the guys selects some tool but I can't see what it is.

    You can fill any closed path by simply setting its fill color in the color palette... Paths can be smoothed with teh smooth tool. Please refer to the online help for specifics. Just watching tutorials doesn't necessarily teach you everything....
    Mylenium

  • How to write the text into text objects

    Hi,
    I have one requirements . from the web we get the delivery line item based pallet numbers info with Quntity .
    How to write the line item level pallet information in the the Delivery line items text element "pallet info" .
    Any function module to write the text data into text elements in SAP like READ_TEXT.
    please give your valuable suggisions .
    Thanks &Regards
    Sai.

    Try:
    CREATE_TEXT
    SAVE_TEXT

  • How to programatically insert values into a object

    I have dynamically created a object.
    cre_fml_str varchar2(32767) := 'CREATE TYPE FML_DAT_ITEMS_OBJ AS OBJECT
    EXECUTE IMMEDIATE cre_fml_str;After that I made a table based on this object.
    And know I make a pipelined table function that should fill and return that table.
    This I have until now.
    CREATE OR REPLACE FUNCTION get_fml_items_dat (pfml_nr in number) return fml_dat_items_ftab pipelined as
       out_rec FML_DAT_ITEMS_OBJ;
       cursor items_dat is
         select d.item_nr, item_dat
         from fml_dat_items d
         where d.fml_nr = pfml_nr;
      begin
         for dat in items_dat
           loop
             null;
           end loop;
      RETURN;
    END;I want to fill the out_rec structure programmatically with the Cursor Loop.
    The Cursor selects two values. One of these values (d.item_nr) is the name of the column of the out_rec.
    And the other value should be the data of these out_rec-column.
    So I need to refence to the columns of the out_rec structure programmatically.
    out_rec."d.item_nr" := d.item_dat; --where d.item_nr should programatically been set.

    I agree with Karthick, this is definitely a recipe for disaster.
    You start by creating a dynamic object.
    You then create a dynamic table based on the dynamic object.
    Then you try to use those dynamically created objects in PL/SQL without using dynamic code.... big mistake.
    But the mistake isn't that you are accessing your dynamic objects incorrectly, the mistake is that you created objects dynamically in the first place. That indicates that your database or application has not been designed properly. The design stage of any database application should determine the objects that are required before you even write any code to use them.
    Yes, you could write dyanmic PL/SQL code to access those objects... but that is generally a stupid thing to do, as it creates non-scalable, bug ridden code that is a nightmare to maintain.
    Better is to step back, start back at the design stage, and correctly design your objects as static objects so that your code can correctly use them with static statements.

  • How to convert bytes[] into File object

    hi
    how to convert byte array into File object
    pls.. help me
    Regards
    srinu

    rrrr007 wrote:
    Hi,
    How to convert bytes[] into multipage File object?? ]There's no such thing as a "multipage File object." You ought to re-read this thread closely, and read the [API docs for File|http://java.sun.com/javase/6/docs/api/java/io/File.html] to clear up your confusion about what a File object is.
    I used the java.io.SequenceInputStream to concatenate two input streams (basically .pdf files) into a single input stream. I need to create a single multipage pdf file using this input stream. Then you need a pdf API, like iText or fop. You can't just concatenate pdf files, word docs, excel sheets, etc., like you can text files. Google for java pdf api.

  • Convery byte[] into a object

    i have a byte[] which I have got from DB. I want to convert it into a object before returning it from a method. There is a wraaper class for byte i.e. Byte. But I am not sure tha how to convert a byte[] into an Object.
    Thanks!!

    georgexu316 wrote:
    corlettk wrote:
    georgexu316 wrote:
    If you know what you are doing, you can perform an implicit conversion by casting the byte.
    byte byteData = new byte();
    Object newObj = (Object) byteData;
    Umm.. Dude, a byte array is-an Object. In Java you don't ever need to explicitly up-cast... but (in order to actually use it as a byte array) you do have to explicitly down-cast it.
    For example:
    package forums;
    class AByteArrayIsAnObject
    public static void main(String[] args) {
    try {
    Object bytes = "Hello World!".getBytes(); // returns a reference to a newly created byte-array-object
    System.out.println( new String((byte[])bytes) );
    } catch (Exception e) {
    e.printStackTrace();
    Well, the person asked to convert it into an Object, maybe he needs it as a object to pass it through another parameter of another method. Even though byte is an extension of Object and you can use all of Object's methods, it wouldn't pass through a parameter of a method that specifies an object.Ummm... Wanna bet?
    package forums;
    class AByteArrayIsAnObjectTest
      public static void main(String[] args) {
        try {
          println(new String((byte[])getBytes("Hello World!")));
        } catch (Exception e) {
          e.printStackTrace();
      private static Object getBytes(String s) {
        return s.getBytes();
      private static void println(Object o) {
        System.out.println(String.valueOf(o));
    }

  • 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)

  • How can I insert values from table object into a regular table

    I have a table named "ITEM", an object "T_ITEM_OBJ", a table object "ITEM_TBL" and a stored procedure as below.
    CREATE TABLE ITEM
    ITEMID VARCHAR2(10) NOT NULL,
    PRODUCTID VARCHAR2(10) NOT NULL,
    LISTPRICE NUMBER(10,2),
    UNITCOST NUMBER(10,2),
    SUPPLIER INTEGER,
    STATUS VARCHAR2(2),
    ATTR1 VARCHAR2(80),
    ATTR2 VARCHAR2(80),
    ATTR3 VARCHAR2(80),
    ATTR4 VARCHAR2(80),
    ATTR5 VARCHAR2(80)
    TYPE T_ITEM_OBJ AS OBJECT
    ITEMID VARCHAR2(10),
    PRODUCTID VARCHAR2(10),
    LISTPRICE NUMBER(10,2),
    UNITCOST NUMBER(10,2),
    SUPPLIER INTEGER,
    STATUS VARCHAR2(2),
    ATTR1 VARCHAR2(80),
    ATTR2 VARCHAR2(80),
    ATTR3 VARCHAR2(80),
    ATTR4 VARCHAR2(80),
    ATTR5 VARCHAR2(80)
    TYPE ITEM_TBL AS TABLE OF T_ITEM_OBJ;
    PROCEDURE InsertItemByObj(p_item_tbl IN ITEM_TBL, p_Count OUT PLS_INTEGER);
    When I pass values from my java code through JDBC to this store procedure, how can I insert values from the "p_item_tbl" table object into ITEM table?
    In the stored procedure, I wrote the code as below but it doesn't work at all even I can see values if I use something like p_item_tbl(1).itemid. How can I fix the problem?
    INSERT INTO ITEM
    ITEMID,
    PRODUCTID,
    LISTPRICE,
    UNITCOST,
    STATUS,
    SUPPLIER,
    ATTR1
    ) SELECT ITEMID, PRODUCTID, LISTPRICE,
    UNITCOST, STATUS, SUPPLIER, ATTR1
    FROM TABLE( CAST(p_item_tbl AS ITEM_TBL) ) it
    WHERE it.ITEMID != NULL;
    COMMIT;
    Also, how can I count the number of objects in the table object p_item_tbl? and how can I use whole-loop or for-loop to retrieve values from the table object?
    Thanks.

    Sigh. I answered this in your other How can I convert table object into table record format?.
    Please do not open multiple threads. It just confuses people and makes the trreads hard to follow. Also, please remember we are not Oracle employees, we are all volunteers here. We answer questions if we can, when we can. There is no SLA so please be patient.
    Thank you for your future co-operation.
    Cheers, APC

Maybe you are looking for