Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

byte[], Byte[], char[], Character[]

I would like to know about byte[], Byte[], char[], Character[]
How the primitives and wrappers are different esp with character and Byte etc.I was not clear on this concept. Thanks in advance
0
gudii9
Asked:
gudii9
  • 5
3 Solutions
 
for_yanCommented:
It is the same as with any other primitive types and their wrappers

byte is primitive

Byte is object wrapper around byte

char is primitive

Character is wrpper around char

one thing that in some
cases it is more convenient to opetarte
with oobjects which can be stored in Collections
can be test on equality to null, etc.

Another thing that these classes
have useful static mthods - say you could
produce byte form String
paarseByte(String s) , etc.

or check Cgharacter.isDigit() etc.


Look in the Byte Aand Character API



 
0
 
for_yanCommented:
0
 
for_yanCommented:
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
dpearsonCommented:
Also in Java a Character (or char) is representing a single Unicode character - which is generally a 16-bit value.

A Byte (or byte) is representing a single 8-bit byte.

So Bytes and Characters are very different concepts.

The difference between byte and Byte and the role of wrappers for_yan has already explained.

Doug
0
 
gudii9Author Commented:
>>>oobjects which can be stored in Collections


can not we store prmitives in collection. please advise
0
 
for_yanCommented:

Collections can contain only objects, they can not contain primitives directly,
though autoboxing makes look so as if it stores the prinmitives

You can write:
        ArrayList<Integer> arint = new ArrayList<Integer>();
       
        arint.add(5);

But in fact compiler makes out of it:

 ArrayList<Integer> arint = new ArrayList<Integer>();
       
        arint.add(new Integer(5));

So primitives cannot be elements of collections


0
 
for_yanCommented:


 ArrayList<int> arint1 = new ArrayList<int>();

This will cause compiler error: Type argument cannot be of primitive type
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now