With respect to an array of string types, the array element does not need to be added ""

Source: Internet
Author: User

With respect to an array of string types, the array element does not need to be added ""

Today, in writing swing, for a quick layout, you need to create a string layout array as shown:

Careful readers may find that the array elements in this border array are not in "", and we know in the learning array that when we define a String array, the elements of the array need to be included in "", for example, we define an array string[]car={"BMW", "Mercedes", " Audi "}; So we have no problem traversing the array.


But if we define STRING[]CAR={BMW, Mercedes, Audi, like the String[]border array above, the program will give an error. To figure this out, you have to understand that string[]car={"BMW", "Mercedes", "Audi"} defines what the "" in the array means. It is equivalent to first defining the array elements as string types, and then adding the array elements to the array. For example if we do not string bmw= "BMW"; BMW it is not a string type, it will naturally complain. In fact, we can also write this:


As you can see, we first define the elements as string, and then we can not add "".

Then we look at the String[]border array above, and the readers of Swing should know that the array element inside is the direction of the boundary layout, and that it belongs to the static String type, as we can see from the code hints. Please see the following code:


As we can see from the output, the Java developer has been string boederlayout.north= "North" at the time of development, so we do not need to add "" in the definition of the string[] array. In the same vein, we can define an array of colors:

This article is the first Blogger blog, I hope to help everyone, if there is a mistake, but also hope that we can correct.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.