2 byte array representation of a string

Posted on 2004-11-12
Last Modified: 2010-03-31
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
Question by:slathakamatchi
    LVL 92

    Expert Comment

    A java char is two bytes

    char[] chars = s.toCharArray();
    LVL 30

    Accepted Solution

    >>  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).

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    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…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now