+ 1

String is what type of data type in java

19th Mar 2019, 7:39 PM
Shasanka Hazarika
3 ответов
+ 15
▪Variables and Data Types There are eight primitive data types in Java: • boolean • byte • short • int • long • float • double • char There are only seven kinds of literals, and one of those is not a primitive data type: boolean b = true; int low = 1; long high = 76L; long middle = 74; float pi = 3.1415292f; double e = 2.71828; String s = "Happy SoloLearning!"; 😊 // There are no short or byte literals! ⟹ Strings are a 'reference' or 'object' type, not a primitive type. The Java compiler has special support for strings so this sometimes appears not to be the case.
19th Mar 2019, 10:56 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 13
• java.lang.String ⟹ Strings are objects. Specifically they're instances of the class java.lang.String. This class has many methods that are useful for working with strings. Internally Java Strings are arrays of Unicode characters. For example the String "Hello" is a five element array. Like arrays, Strings begin counting at 0. Thus in the String "Hello" 'H' is character 0, 'e' is character 1, and so on . . . as Théophile said!👍😉
19th Mar 2019, 11:10 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 2
Strings are arrays of char terminated by the value 0. For instance, the string "hello" is equal to (in c) : char str[] = {'h', 'e', 'l', 'l', 'o', 0}; Just remember strings are arrays, that's all!
19th Mar 2019, 8:21 PM
Théophile
Théophile - avatar