Int and Integer

whats the difference between these two anyway..?

int is a primitive type and Integer is a class. You would generally use primitive types wherever possible because they are much more efficient. You would use classes, for instance, if you have to put your values into a collection such as an ArrayList.

Similar Messages

  • I am confused..what is Boolean and Integer?

    What is the difference between Boolean and bolean and Integer and int?

    you can think of it this way
    // this is an Object
    public class Boolean {
    public Boolean{
    boolean status = false;
    and
    // this is a primitive
    boolean status = false;
    Both of these code would create a variable called status which would be initialized to false. The difference would be that one is an Object, the other a primitive.
    With primitives, specifically boolean, you can only do a few things to it. e.g. change the variable status to true or false.
    But with an Object of class Boolean you can do the simple conversion from false to true plus more, depending on what you want it to do (using method to act upon the object).
    For the int and Integer,
    Integer numberObject = new Integer(3);
    this would create an Object of class Integer with a parameter 3 in it.
    int numberPrimitive = 3;
    would be the primitive equivalent.
    numberObject.intValue();
    would convert the Integer object to a primtive that returns 3 for its value.
    for numberPrimitive you can probably change it to say 4, 5, 3490, 45 +546, 245/ 34543 ......whatever...
    hope this helps... =P

  • String to Int and Int to String

    How can I convert a string to Int & and an Int to String ?
    Say I've
    String abc="234"
    and I want the "int" value of "abc", how do I do it ?
    Pl. help.

    String.valueOf(int) takes an int and returns a string.
    Integer.parseInt(str) takes a string, returns an int.
    For all the others long, double, hex etc. RTFM :)

  • Invalid casts - Object and Integer

    OK, I have got myself confused with casts. I have written this code, which I have [bold]SUBMITTED[bold] to University (so if you change it you are not helping me cheat...) . It doesn't compile and I am out of ideas why. The problem is the last method returnEvenNumbers(). Please could someone help me learn how this should be used by turning this into running code.
    * Filename: RandomNumberArray.java
    * Author: Steven Lane
    * Email: [email protected]
    * Created on 17 February 2002, 17:53
    * Course: KIT eLearning, MSc in IT, University of Liverpool, UK
    *         MSC-JV0020110-03
    * Purpose: This class creates an uncostrained array of length L passed as int on instantiation.
    *          The array is populated with (pseudo) random numbers.
    *          Methods contain a filter for even numbers, which is pushed onto a stack.
    * Version: 0.2
    //package com.thinkcorporation.week6;
    // ------------------- Import Packages -------------------
    import java.util.*;
    // ------------------- Class Heading -------------------
    public class RandomNumberArray extends java.lang.Object {
        // ------------------- Field Defintions -------------------
       private Stack stkEvenNumbers = new Stack();
        private int [] rndNoArray;
        //private int [] evenNoArray;
        private Integer evenNoArray[];
        // ------------------- Constructors -----------------------
        public RandomNumberArray(int length) {
            rndNoArray = new int [length];
            populateRndNoArray();
        //------------------- Methods -----------------------------
        private void populateRndNoArray() {
            Random rnd = new Random();
            for(int counter = 0; counter < rndNoArray.length; counter++) {
                rndNoArray[counter] = rnd.nextInt();
        public void evenNumberFilter() {
            for(int counter = 0; counter < rndNoArray.length; counter++) {
                if (rndNoArray[counter]%2 == 0)
                    stkEvenNumbers.push(new Integer(rndNoArray[counter]));
        public int [] returnEvenNumbers() {
            if (!stkEvenNumbers.empty()) {
                evenNoArray = new Integer [stkEvenNumbers.size()];
                evenNoArray = (Integer)stkEvenNumbers.toArray();
            return evenNoArray;
    }You help is much appreciated.

    The root of the problem is a difference between primitive types and objects. The Stack.toArray() method returns an array of Objects (Object[]), which you can cast to an array of Integer objects (Integer[]):
    evenNoArray = (Integer[])stkEvenNumbers.toArray();However, your return type for that method is int[] - a primitive types, not objects. Meaning that you either have to step through the array and build an array of ints (using Integer.intValue()), or you have to change the return type of your method.

  • How do you test if a string could be a valid int and then convert to int?

    Hello, my name is Esran41 and I'm new to this site. I'm in computer science one this year and our current assignment is to make a console based Tic-Tac-Toe game. The final program must be able to detect errors in the user's input. For example, if the program asked the user for an int and he typed a character, our program must recognize this, print an error message, and then prompt him for the int again. I also need to know some common string manipulation methods(like String.length) and their syntax too. Again, I'm extremely new to java, so please include code fragments and example programs to demonstrate these methods.
    To sum-it-up, I need to know how to do the following(The syntax):
    Method (1)
    - test an inputed string to see if it's a valid integer
    - report an error to the user if it's not a valid integer
    - if there was an error, prompt the user again
    Method (2)
    - Pass the inputed string as a parameter
    - Convert the string into an integer
    - return the integer
    Also, what is a try-catch statement, what does it do, and how is it implemented?
    Please post any advice or help that you may have pertaining to my problems.
    Thanks!

    Do not insult me. If I could read my computer science
    book, I would. Please don't insult yourself... by pointing out your limitations...
    I will apologize for my cynical remarks... You should see how many requests for " I need help" where the answer could be found so easily...
    But it is quite obvious that you have access to the internet... If you did a search for Java, eventually you would find yourself as Sun's web site... Which means that you would have arrive at this page...
    http://java.sun.com
    and towards the bottom left had corner of that page you would find these links...
    Learning
    New to Java Center
    - Tutorials & Code Camps
    - Online Sessions & Courses
    - Course Certification
    - Instructor-Led Courses
    - Quizzes
    And you will find the same resources that I am using to learn Java...
    I'm looking up this information not only for myself, but for my class too....
    Thus, we are stuck with old computers, about twenty books for 220 kids, and one teacher who is great at >C++, but knows nothing about java.Then print out the Java documentation, goto Kinko's and make copies so that your class can have the reference material available to them, or ask your teacher to... Since he/she will need to learn the language also... But since they have programming experience they will be better able to explain the concepts of programming that you do not understand...
    You can make any excuse for why it is difficult for you to learn, but in the end its totally irrelevant... If the school district cannot provide funding for class material, then instead of complaining with " I don't have a book... " start a community fund raiser to purchase those materials... Goto to the public library and see if they have resources you and your class can utilize... After all, it is your responsibility to educate yourself...
    And most important of all, never ever say anything negative or limiting against yourself...
    Do not insult me. If I could read my computer science book, I would. This is a statement against yourself... What does this statement tell you about yourself... You stated that I should not judge, but here you made a judgement about your own ability to learn...
    To even insinuate that I skip class is an outrage to me. You should watch your tongue and not be so >quick to judge a situation.Why, do you ? Apparently I touched a nerve somewhere... But that does not matter...
    Are you really concerned with what I think of you... If you are then you are a fool...
    What other think or say have nothing to do with you... Do you know me, do I know you...
    The answer is clear... I can give it to you... The Answer is No.
    If you want to learn then learn... Read, Research, Practice and Read again... So simple...
    Anyway... Have fun... Check out the tutorials, learn how to use the API documentation and practice coding...
    and here are those links again...
    The Java Tutorial
    http://java.sun.com/docs/books/tutorial/index.html
    Essentials of the Java Programming Language: A Hands-On Guide, Part 1 and 2
    http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/
    http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/
    Language Essentials Short Course
    http://java.sun.com/developer/onlineTraining/JavaIntro/contents.html
    Others
    The Java Tutorial
    http://java.sun.com/docs/books/tutorial/index.html
    Tutorial Index
    http://java.sun.com/developer/onlineTraining/index.html
    - MaxxDmg...
    - ' He who never sleeps... '

  • Converting int[] to Integer[]

    How to convert an int array to Integer[] without iterating the int[]?
    we can traverse the int[] and add to Integer[]. But the traversing takes too much time. Is there any method to do the above conversion?

    If you are using 1.5, you can use the individual elements of the int[] as if they were an Integer, so why do you need to convert it? If it is to pass the array as an argument, then sorry, you are going to have to traverse the arrays and set the elements. And, at most, this will take a second or two of time (even if you have an array of nearly max size), so in what way is this "taking too much time"?
    Edit: And any API method to do this with a single line of code, would still, inside the method, need to traverse the arrays, so now time would be saved. If it is to save programming time, then take a few minutes to write a method for it now, and then every time you need it in the future, just use that method.

  • Counter KF with 1 & 0 and difference between data type NUMBER (DEC) and INTEGER (INT4)

    Hi,
    I need to create a counter kf which should populate 1 and 0 to this counter field. Please let me know is there any difference between data type
    NUMBER (DEC) and INTEGER (INT4).
    Please suggest.
    Thanks & Regards,
    Pavan kumar

    Hi Pavan,
    The basic difference between Number(DEC) and INT4 is its internal storage in system.
    For Number (DEC) - Value internally stored as packed number with 3 decimal places whereas INT 4 as 4 byte integer without decimal places.
    For counter KF, you can go for INT 4.
    Hope this helps.
    Thanks

  • From bit array (boolean[]) to int and back

    (First of, I have searched hi and low, and have only found bits to bytes examples.)
    Simple question folks, I hope.
    How to convert a boolean[] array to an int or Integer, and from an int to a boolean array?
    I wouldn't mind using BitSet instead of primitives if that would help, but that api also does not supply a quick toInteger or valueOfInteger method.
    Please advise.
    Thanks, nat.

    You could use the bitwise operators:
    http://java.sun.com/docs/books/tutorial/java/nutsandbo
    lts/bitwise.html
    Especially see the part about "flags".Am aware of that and indeed use this. However, sometimes a boolean array is more convenient or a must (using the "flags", my constants have to be 2,4,8,16,32,64,128...) and
    I am dealing with a class that already has constants from 1 thru 21, and I want to add on to that class a boolean per constant, to track stuff I am adding to that class.
    Anyhow, is it THAT complex to convert from a boolean array to an int?
    nat

  • Separate the int and decimal parts of a double var

    Hi,
    I would like to know how can I obtain the int part and decimal of a double var.
    Example:
    2.3455
    int -->2
    decimal--->3455
    Also I would like to know how I can specify the precision of the decimal part. For example: 3455 if want a 2 decimal precision--> 34
    Regards and thanks with anticipation.

    Hi all,
    I too have a way to this solve this.
    1. Convert the double into a string.
    2. Split it by . symbol, which will produce an array of two elements.( First one is integer part, another one is decimal part)
    3. Now we can easily do type casting and get two variables.
    Example:
    double base = 2.5689;
    String str = Double.toString(base);
    String[] out = null;
    out = str.split(".");
    int a = Integer.parseInt(out[0]);
    double b = Double.parseDouble(out[1]);Thanks
    Ram

  • Difference between int and byte

    what is the main difference between int and byte?

    A byte is the format data is stored in memory in past. 8 bits.
    An int is a format likewise you get it as value from the accumulator. For X64 that is Int64.
    For compatibility the "Integer" is kept currently on Int32, the register format from the X86 computers. 
    Older computers likewise the 8088 had an 8 bit Int and therefore that was the same as the byte.
    The 80286 had a 16 bits Integer.
    Success
    Cor

  • Parsing ints and longs

    I am trying to parse a String that indicates 8 hex characters and store the result in an integer. I have the following code:
    String s = "cafebabe";
    int i = Integer.parseInt(s, 16);This throws a NumberFormatException, apparently because the numerical value is negative. I can work around it by doing this:
    String s = "cafebabe";
    int i = (int)Long.parseLong(s, 16);
    /code]
    But what about when I'm parsing a long?  I have this code:String s = "cafebabedeadbeef";
    long val = Long.parseLong(s, 16);
    Again, this throws a NumberFormatException.
    Any solution to the second case? Any way of making the first case cleaner? It's frustrating that I can't simply stuff 32 or 64 bits with the hex characters that I want. I would also like to avoid redefining my String as "-35014542" (the negative of "cafebabe").

    > String s = "cafebabedeadbeef";
    long val = Long.parseLong(s, 16);long val = new BigInteger(s,16).longValue();

  • Chart Error - scroller positions should be positive and integer

    <p>
    Hello Expert
    I have created a flash chart with two filters on the chart region.
    i) &lsquo;Select list with submit' ----- (:P23_TRC)
    ii) &lsquo;Radio button with submit' -----(:P23_IMPACTC)
    The chart should display as per the filters selection.
    However, I get the error message "<strong>scroller positions should be positive and integer</strong>", once, whenever I load this chart page for the 1st time in a new IE window.
    After I change the filter's value it will work perfectly fine.
    In filters default value is one value from respective filter list of value
    </p>
    <p>
    If I remove the filter conditions from chart query, it works perfectly without error.
    <u>Here are my chart series queries</u>
    select null link, V.LOB label, COUNT(TR) "Customer Care"
    from V_PROCESSTRACKING V
    Where V.ProcessArea like '%Customer Care%' and (V.TR = :P23_TRC) AND ((V.IMPACT = :P23_IMPACTC)OR (:P23_IMPACTC = 'ALL'))
    group by V.LOB
    order by V.LOB
    select null link, V.LOB label, COUNT(TR) "Sales"
    from V_PROCESSTRACKING V
    Where V.ProcessArea like '%Sales%' and (V.TR = :P23_TRC) AND ((V.IMPACT = :P23_IMPACTC)OR (:P23_IMPACTC = 'ALL'))
    group by V.LOB
    order by V.LOB
    <u>Customer XML</u>
    &lt;?xml version = "1.0" encoding="utf-8" standalone = "yes"?&gt;
    &lt;root&gt;
    &lt;type&gt;
    &lt;chart type="Stacked Horizontal 3DColumn"&gt;
    &lt;animation enabled="yes" appearance="size" speed="10" /&gt;
    &lt;hints auto_size="yes"&gt;
    &lt;text&gt;&lt;![CDATA[{NAME}, {VALUE}]]&gt;&lt;/text&gt;
    &lt;font type="Verdana" size="10" color="0x000000" /&gt;
    &lt;/hints&gt;
    &lt;names show="no"/&gt;
    &lt;values show="no" prefix="" postfix="" decimal_separator="." thousand_separator="," decimal_places="0" /&gt;
    &lt;arguments show="no" /&gt;
    &lt;column_chart column_space="3" block_space="12"&gt;
    &lt;border enabled="no" /&gt;
    &lt;block_names enabled="yes" placement="chart" position="left" &gt;
    &lt;font type="Verdana" size="10" color="0x000000" /&gt;
    &lt;/block_names&gt;
    &lt;/column_chart&gt;
    &lt;/chart&gt;
    &lt;workspace&gt;
    &lt;background enabled="yes" type="solid" color="0xffffff" alpha="0" /&gt;
    &lt;base_area enabled="no" /&gt;
    &lt;chart_area enabled="yes" x="215" y="50" width="705" height="500" deep="0"&gt;
    &lt;background enabled="no"/&gt;
    &lt;border enabled="yes" size="1"/&gt;
    &lt;/chart_area&gt;
    &lt;x_axis name="Line of Business" smart="yes" direction="horizontal" rotation="-90" position="left_center" &gt;
    &lt;font type="verdana_embed_tf" size="14" color="0x000099" bold="yes" align="center" /&gt;
    &lt;/x_axis&gt;
    &lt;y_axis name="No. of Process" smart="yes" position="center_bottom" &gt;
    &lt;font type="Verdana" size="14" color="0x000099" bold="yes" align="center" /&gt;
    &lt;/y_axis&gt;
    &lt;grid&gt;
    &lt;values /&gt;
    &lt;/grid&gt;
    &lt;/workspace&gt;
    &lt;legend enabled="yes" x="935" y="50"&gt;
    &lt;names enabled="yes"&gt;
    &lt;font type="Verdana" size="9" color="0x000000" bold="yes"/&gt;
    &lt;/names&gt;
    &lt;values enabled="no"/&gt;
    &lt;scroller enabled="no"/&gt;
    &lt;header enabled="no"/&gt;
    &lt;background alpha="0"/&gt;
    &lt;/legend&gt;
    &lt;/type&gt;
    #DATA#
    &lt;/root&gt;
    <strong>Help please!!!!! It's urgent</strong>
    Sagar
    </p>

    Hi Rima,
    I found the solution,
    My graph is dependent on the page items. What I found was when I load the page, item default value was displayed but it was not stored in the memory. Item value only gets stored in memory when the page is submitted.
    Line: -----
    Soultion : - Create a page level before header process and define the default value over here as well. This will resolve your error.
    Hopefully you understood what I am trying to explain. If not let me know and I will trying to put in picture and email you.
    Sagar

  • Oracle.jbo.domain.Number to int and back

    I have a database field that comes back as a oracle.jbo.domain.Number.
    I want to increment this by one so was trying to convert it to an int, apply the increment then turn it back into a number.
    2 questions :
    1) Can I increment oracle.jbo.domain.Number directly
    2) If not how to I turn it to an int and back
    Many thanks,
    Richard

    Convert oracle.jbo.domain.Number to int with the intValue method.
    oracle.jbo.domain.Number var;
    int intValue=var.intValue();Convert int to oracle.jbo.domain.Number with the Number (int value) constructor.
    int intValue;
    oracle.jbo.domain.Number var=new oracle.jbo.domain.Number(intValue);

  • Overloading ambiguity between "std::pow(double, int)" and "std::pow(long do

    hello all,
    we have a problem with sources coming from visual c++, i can reproduce the problem with the small code:
    $ cat test.cc
    #include <math.h>
    int main()
    double kk;
    int j11;
    j11=4;
    kk=pow(2,j11);
    $ CC test.cc
    "test.cc", line 8: Error: Overloading ambiguity between "std::pow(double, int)" and "std::pow(long double, int)".
    1 Error(s) detected.we are on linux, with sun studio 12u1
    thanks in advance for help,
    gerard

    The issue is whether the standard headers associated with the compiler have the overloads required by the standard. If the required overloads are present, the original call of std::pow is ambiguous, and the compiler will report it.
    If you have a recent version of Visual C++, I'd be very surprised if the function overloads were not available. Possibly you are using a compiler option, perhaps a default option, that hides the overloaded declarations. In that case, some C++ code that conforms to the standard would not behave correctly when used with the compiler in that mode.
    The correct approach is to use the compiler in standard-conforming mode so that code you write will be accepted by other standard-conforming compilers. That is, after all, the purpose of the standard.

  • Help with unsigned ints and how to store and retrieve data in them

    Hi all
    I have a problem where some data is being stored in an unsigned int
    i dont really know much about them and am unsure on how to go about using the data.
    The data being stored in them is row and column information in an excel spreadsheet.
    The method is passed through 2 ints (column, row) and then a unsigned int is created out of these two values
    the column is 8 bits and shift to the left hand byte (column & 0xFF <<24)
    the row is 16 bits shifted to the right of the column (row & 0XFFFF <<8)
    so if the column and row were 1,1 then the unsigned int would be
    16777472
    and for 1,2 then it would be 16777728
    (i dont actually know how these numbers are formed, it would be great if someone can explain this too :) )
    anyway now i have those unsigned int numbers does anyone know how i would go about taking that unsigned int and getting my int back from it
    so take 16777728 and extracting column 1, row 2
    any help would be appreciated

    its not a 3rd party product, its been written by
    another peep who is on holiday for 2 weeks so im
    trying to sort something out but dont really
    understand unsigned ints and stuff :(This is what is called a "third party product". It's not written by Sun, and it's not written by you.

Maybe you are looking for

  • Tax rate is not coming up in PO

    Hi, The rate is not coming for one of the tax condition type in the PO 1)Tax percentage 12 percent is maintained against the condition type in FV11. 2)Calculation schema is proper. 3) Tax code is maintained properly . this problem has arised after mi

  • Correct version of jdeveloper to use with Oracle App Server 10g 10.1.2.0.2

    Hi, I just want to be sure, I am new to JDeveloper and I would just like to verify/ask what correct version of JDeveloper should we use so we could deploy the finished applications on our Oracle Application Server 10g 10.1.2.0.2 without errors? Looki

  • Bizzare behavior with RMI using the localhost

    I'm still new to RMI and I'm observing some strange behavior with RMI. I'm using RMI as a communication protocol in a client/server database application. Since I don't have access to a network at the moment I was running the application on a single h

  • Upgrading from photoshop 9 to 12

    Hi All several questions:- 1. when I install 12 what to 9 and photos stored in 9? 2. How do i get photos from 9 to 12 if not done on install 3. Once installed should i delete 9 I would like a step by step instruction if the process is not as simple a

  • Scroll to top of a page

    Hi, When pressng the Page Up or Page Down keys, I don't go exactly to the top of the previous or next page. This means that I often end up looking at half the top and half the bottom page. Is there a command to go exactly to the beginning of the next