2 byte array representation of a string

Dear Experts,

In Modula programming labguage, any string (array of chars) can be mapped to a array of cardinal type.A cardinal type can hold 2 bytes.

So a string can be mapped to a array of 2bytes values.

In java, I can split the String into individual single bytes (String.getBytes()).

But I need to simulate the same functiionality as in modula.
i.e, i need to get the array of 2 bytes values of a string.

Could anybody suggest me the means?

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A java char is two bytes

char[] chars = s.toCharArray();
Mayank SAssociate Director - Product EngineeringCommented:
>>  need to get the array of 2 bytes values of a string.

You don't use getBytes () for that. You generally use getBytes () while transferring the data through a network using sockets, etc (just an example - there could be more).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

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.