(阵列和放大器;字符串)的差异在Java中对丙 [英] (array & string) Difference in Java vs. C

查看:125
本文介绍了(阵列和放大器;字符串)的差异在Java中对丙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道C和我进入Java和困惑,其对数组和字符串的方法。这是从C.数组和字符串完全不同的,请帮助我了解什么是真正的C和Java之间的差异(字符串和数组)。

I know about C and I am entering into Java and confused about its approach towards arrays and strings. It's totally different from arrays and strings in C. Please help me understand what is actually the difference between C and Java (for strings and arrays).

推荐答案

在C,一个字符串通常只是一个数组(或指向)字符,用NUL(\\ 0)字符结束。您可以处理一个字符串,你会处理任何阵列。

In C, a string is typically just an array of (or a pointer to) chars, terminated with a NUL (\0) character. You can process a string as you would process any array.

在Java中,但字符串不是数组。 Java字符串是 java.lang.String中类的实例(对象)。他们重新present字符数据,但是内部实现不暴露给程序员。你不能把他们当作阵列,虽然,如果需要的话,可以提取字符串数据以字节或字符数组(方法的getBytes 则GetChars )。还需要注意的是Java的字符是16位的,总是,而用C字符通常(不总是)8位。

In Java, however, strings are not arrays. Java strings are instances (objects) of the java.lang.String class. They represent character data, but the internal implementation is not exposed to the programmer. You cannot treat them as arrays, although, if required, you can extract string data as an array of bytes or chars (methods getBytes and getChars). Note also that Java chars are 16-bits, always, while chars in C are typically (not always) 8-bit.

这篇关于(阵列和放大器;字符串)的差异在Java中对丙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆