Confused on when to use Character vs. char in Java? [duplicate] - java

This question already has answers here:
Why do people still use primitive types in Java?
(21 answers)
When to use wrapper class and primitive type
(11 answers)
Closed 2 years ago.
I know that char is a primitive type while Character is a class, but I'm confused on when to use which? Is there a good rule of thumb for this?

Related

Why use int instead of Integer (or the other way around) in Java? [duplicate]

This question already has answers here:
When to use wrapper class and primitive type
(11 answers)
What is the difference between Integer and int in Java?
(11 answers)
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
I know that Integer is a class and int is just a number, but when should we use one over another and how to convert Integer to int (and vice versa)?
** Also, there is this
question (what is autoboxing by the way) but I am asking WHEN to use int over Integer in actual programming (such as performance issues, ease of use and readability) and vice versa and not the DIFFERENCE between them.

Character vs char with arrays and array lists? [duplicate]

This question already has answers here:
Why can Java Collections not directly store Primitives types?
(7 answers)
Closed 2 years ago.
Why are Character arrays not valid, but char arrays are, and why are Character lists valid, but char lists not? This probably has something to do with primitives vs objects, but can someone explain it more clearly?
both char[] and Character[] are perfectly valid. When it comes to generics, though, (like those in List<T>), the generic parameter must be a class and not a primitive, so you can only have List<Character>.

Java augment strings to string [duplicate]

This question already has answers here:
Java Equivalent to .NET's String.Format
(6 answers)
String replacement in java, similar to a velocity template
(12 answers)
Closed 4 years ago.
I need to augment some string like it's done by logback/famous loggers or property accessors.
String str= "I can {0} give {1} back your horses or restore your {2} to life.";
String[] got=new String[]{"not","you","dead"};
Are they any utility functions provided by any library that can convert str to replace {i} with indices in array?
Its most probably a duplicate and please refer me to some similar question.

how to store "12000000000" or a 11 digit number in java [duplicate]

This question already has answers here:
Large Numbers in Java
(6 answers)
Closed 6 years ago.
given here only as a form of validating.Which data type to use to store such a big number
Probably what you're looking for is BigInteger, BigDecimal if you want decimals instead.

How is unboxing done in Java? [duplicate]

This question already has answers here:
How does auto boxing/unboxing work in Java?
(4 answers)
Closed 7 years ago.
I know how boxing is done. For example, when you write Integer a = 4, Integer.valueOf(int) is being called. Likewise, can i see the implementation code for unboxing as well?
Update : It is answered in the suggested question.
In such cases,intValue() gets called to get the primitive value.
Integer a= new Integer(4);
int val = a.intValue();
Like the integer, all the wrapper classes have this method to get it's primitive value.

Categories