Solved

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

Posted on 2011-09-06
7
360 Views
Last Modified: 2012-05-12
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
Comment
Question by:gudii9
  • 5
7 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 334 total points
ID: 36492786
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
 
LVL 47

Expert Comment

by:for_yan
ID: 36492791
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36492801
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 26

Assisted Solution

by:dpearson
dpearson earned 166 total points
ID: 36493173
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
 
LVL 7

Author Comment

by:gudii9
ID: 36584426
>>>oobjects which can be stored in Collections


can not we store prmitives in collection. please advise
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36584450

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
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 334 total points
ID: 36584462


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

This will cause compiler error: Type argument cannot be of primitive type
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
network + 7 80
Java. Convert method from recursion based to iteration based ( loop based ) 6 76
mockito example issue 8 62
Error trying to install RTMT Win7 5 41
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now