You have actually been using the String data type for quite some time and to a large degree you may think that it was a or data type. This is not simple primitive surprising. Consider the variable declarations in figure 12.1. Figure 12.1 int number; char letter; double gpa; boolean finished; String title; You see five declarations and each declaration starts with a data type followed by a variable identifier. It appears that all five of the declarations behave in the same way. You may note one peculiar difference; the String declaration is the only data type that starts with an letter. Now look at the value assignments upper-case for each one of the variables in figure 12.2. Figure 12.2 number = 2500; letter = 'A'; gpa = 3.785; finished = true; title = "Exposure Java"; The assignment statement seems to give secondary evidence that belongs String with the simple data types. By now you have seen that data structures behave quite differently from simple data types. Accessing any element in an array requires not only the array identifier, but also an index to access a specific array element. Access of any field in an object, which is an attribute of an object in requires the object identifier and some accessing method. Java, There appears lots of evidence that the data type is a very convenient and String lovely data type. It is true that a string stores multiple characters, but after simple all you have treated a string like a single unit. The true nature of strings has intentionally been hidden. During the early chapters you have benefited very nicely by treating and using strings as if they were no different from the other simple data types. Now that you have started to learn about data structures and you have been exposed to a fair amount of Object Oriented Programming, the truth can be told.
You have actually been using the String data type for quite some time and to a large degree you may think that it was a simple or primitive data type. This is not surprising. Consider the variable declarations in figure 12.1. Figure 12.1 int number; char letter; double gpa; boolean finished; String title; You see five declarations and each declaration starts with a data type followed by a variable identifier. It appears that all five of the declarations behave in the same way. You may note one peculiar difference; the String declaration is the only data type that starts with an upper-case letter. Now look at the value assignments for each one of the variables in figure 12.2. Figure 12.2 number = 2500; letter = 'A'; gpa = 3.785; finished = true; title = "Exposure Java"; The assignment statement seems to give secondary evidence that String belongs with the simple data types. By now you have seen that data structures behave quite differently from simple data types. Accessing any element in an array requires not only the array identifier, but also an index to access a specific array element. Access of any field in an object, which is an attribute of an object in Java, requires the object identifier and some accessing method. There appears lots of evidence that the String data type is a very convenient and lovely simple data type. It is true that a string stores multiple characters, but after all you have treated a string like a single unit. The true nature of strings has intentionally been hidden. During the early chapters you have benefited very nicely by treating and using strings as if they were no different from the other simple data types. Now that you have started to learn about data structures and you have been exposed to a fair amount of Object Oriented Programming, the truth can be told.
Text12-StringsMethods.docx