autoboxing Questions
3
Solved
As Java 5 have autoboxing, why I can't use Comparator to sort primitives? An int wouldn't be wrapped into a Integer?
Geodesy asked 29/12, 2010 at 21:38
21
Solved
How do I convert int[] into List<Integer> in Java?
Of course, I'm interested in any other answer than doing it in a loop, item by item. But if there's no other answer, I'll pick that one as ...
Tamer asked 2/7, 2009 at 11:47
3
Solved
I couldn't find a definitive answer for this seemingly simple question. If I write a method like this:
public Integer getAnInt() {
int[] i = {4};
return i[0];
}
is the return value autoboxed int...
Unthinkable asked 12/8, 2022 at 15:1
2
Solved
I came across https://code.google.com/p/hamcrest/issues/detail?id=130 to add some sugar syntax for Hamcrest matchers. But the idea was rejected by the Hamcrest developers.
Any other smart ideas to...
Everglades asked 18/10, 2014 at 8:40
1
Solved
I want to compare a long value (primitive type) with another Long value (wrapper type):
long x = 5;
Long y = 5L;
// version 1: only safe, if x is a primitive type
var isEqual = x == y;
// version...
Lynwoodlynx asked 10/11, 2021 at 10:53
1
Solved
public class Playground {
public static void main(String[] args) {
String s = "blah";
Character lclfs = s.contains("/") ? '/' : s.contains("\\") ? '\\' : null...
Mayonnaise asked 13/10, 2021 at 8:19
10
Solved
Autoboxing is the automatic conversion that the Java compiler makes
between the primitive types and their corresponding object wrapper
classes. For example, converting an int to an Integer, a d...
Tetrachord asked 25/12, 2014 at 12:59
12
Solved
I just saw code similar to this:
public class Scratch
{
public static void main(String[] args)
{
Integer a = 1000, b = 1000;
System.out.println(a == b);
Integer c = 100, d = 100;
System.out...
Rowlett asked 28/6, 2010 at 5:43
1
JLS §5.2 of Java SE 11 contains some new type conversion cases which JLS of Java 8 doesn't have, see item 4 and item 5 in the list:
Assignment contexts allow the use of one of the following:
an i...
Feleciafeledy asked 30/8, 2020 at 22:53
21
Solved
Since Java 5, we've had boxing/unboxing of primitive types so that int is wrapped to be java.lang.Integer, and so and and so forth.
I see a lot of new Java projects lately (that definitely requir...
Gunlock asked 4/3, 2011 at 21:16
4
Solved
To my understanding following code should print "true", but when I run it it prints "false".
public class Test {
public static boolean testTrue() {
return true;
}
public static void main(Stri...
Dolora asked 8/1, 2019 at 8:17
10
I know that if you compare a boxed primitive Integer with a constant such as:
Integer a = 4;
if (a < 5)
a will automatically be unboxed and the comparison will work.
However, what happens when ...
Disestablish asked 3/10, 2009 at 21:30
4
Solved
Run the following Java code:
boolean b = false;
Double d1 = 0d;
Double d2 = null;
Double d = b ? d1.doubleValue() : d2;
Why is there a NullPointerException?
Splint asked 16/7, 2010 at 14:36
4
Solved
Since JDK 5.0, auto boxing/unboxing was introduced in Java. The trick is simple and helpful, but when I started testing different conversions between wrapper classes and primitive types, I get real...
Aguascalientes asked 25/3, 2014 at 23:41
3
Solved
public class WrapperClasses{
void overloadedMethod(Number N){
System.out.println("Number Class Type");
}
void overloadedMethod(Double D){
System.out.println("Double Wrapper Class Type");
}
...
Sheath asked 7/9, 2018 at 7:25
1
Solved
I'm new to JAVA, currently learning Oracle tutorial generics section. I think there is a mistake there, and I want to make sure I'm not wrong. I'll appreciate your feedback.
I saw the follow...
Dnieper asked 1/8, 2018 at 13:42
12
Solved
In Java, you would usually say that
if(someBool != false)
is the same as
if(someBool)
But what if someBool is not of type boolean but Boolean, and its value is null?
Laxation asked 30/11, 2010 at 12:4
2
Solved
I have the code below throwing IndexOutOfBoundsException:
List<Character> list = new ArrayList<>();
char c = 'a';
list.add(c);
list.remove(c); // gets fixed by passing list.remove...
Analysand asked 2/4, 2018 at 19:14
4
Solved
Is there any way to use autoboxing for the classes I create? For example, I have this subclass of Number.
public class UnsignedInteger extends Number {
int n;
public UnsignedInteger(int n) {
i...
Disendow asked 12/7, 2013 at 16:35
5
Solved
Widening and Boxing Java primitives.
I know it is not possible to widen a wrapper class from one to another as they are not from the same inheritence tree. Why though is it not possible to widen ...
Itinerate asked 10/8, 2011 at 16:15
1
Solved
What is the difference between these 2 codes:
Arraylist<Integer> listofIntegers = new Arraylist<Integer>();
listofIntegers.add(666);
System.out.println("First Element of listofIntegers...
Evalynevan asked 14/1, 2018 at 16:9
1
Solved
There is no error during auto-boxing of constants with int and short types to Byte, but constant with long type do has error. Why?
final int i = 3;
Byte b = i; // no error
final short s = 3;
Byte...
Flowered asked 13/9, 2017 at 20:26
6
Solved
I have refer to this before posting this Question.
Checking Null Wrappers against primitive values
And I have situation that I want to check Wrapper Integer with null as well 0
if( statusId != n...
Horizontal asked 24/7, 2017 at 11:2
3
Solved
Please help me understand this piece of code in the kotlin docs:-
val a: Int = 10000
print(a === a) // Prints 'true'
val boxedA: Int? = a
val anotherBoxedA: Int? = a
print(boxedA === anotherBoxedA...
Distiller asked 17/7, 2017 at 8:30
7
Solved
I'm a newbie Java coder and I just read a variable of an integer class can be described three different ways in the API. I have the following code:
if (count.compareTo(0)) {
System.out.println(...
Lashondra asked 4/6, 2009 at 21:21
1 Next >
© 2022 - 2024 — McMap. All rights reserved.