How can i cast Integer to int? I was working in eclipse and the casting to (int)
ID: 3863942 • Letter: H
Question
How can i cast Integer to int?
I was working in eclipse and the casting to (int) worked.
but when i changed it into eclipse it says I can't cast Integer into int.
So I deleted the (int) and it says I cannot compare Object with Object
the given arraylist is
private Integer[]theItems;
sorting array public void sort int j boolean flag true set flag to true to begin first pass Integer temp //holding variable while flag flag false //set flag to false awaiting a possible swap for j 0; size -1: j++ if int) the Items [j]> (int) the Items [j+l] temp the Items the Items [j] the Items [j+1] the Items [j+1] temp //change element order flag trueExplanation / Answer
We can't direct typecast Integer object to int directly like above in the program I.e.(int)theItems[i].
To convert Integer object to int value we have to use Wrappers class concept.
I.e. to convert Integer object to int we have to use intValue() method.
For example, Integer i = new Integer (10);
int intValue =i. intValue();
In the above example try to use like this
if (theItems[j].intValue())>(theItems[j+1].intValue())
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.