Solved

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

Posted on 2011-09-06
7
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 27

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 242
hibernate insert example 13 40
IntelliJ and Eclipse Neon 2 installations 4 41
Java pass by reference 3 25
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

730 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