Home > Common Problem > body text

What are the methods of assigning values ​​to string arrays?

小老鼠
Release: 2023-12-25 17:07:17
Original
2053 people have browsed it

The assignment methods of string arrays in common programming languages: 1. Python: "string_array = ["apple", "banana", "cherry"]"; 2. Java: "String[] stringArray = { "apple", "banana", "cherry"}"; 3. C and so on.

What are the methods of assigning values ​​to string arrays?

#In programming, the assignment method of string arrays will vary depending on the programming language. Here, I will give some ways to assign string arrays in common programming languages:

1, Python:

string_array = ["apple", "banana", "cherry"]
Copy after login
Copy after login

2, Java:

String[] stringArray = {"apple", "banana", "cherry"};
Copy after login

or in Java 9 In and above versions, you can also use:

List list = Arrays.asList("apple", "banana", "cherry");

3. C :

#include <string>  
#include <vector>  
  
std::vector<std::string> stringArray = {"apple", "banana", "cherry"};
Copy after login

Or use C-style string array:

char* stringArray[] = {"apple", "banana", "cherry"};
Copy after login

4, JavaScript:

let stringArray = ["apple", "banana", "cherry"];
Copy after login

5, C#:

string[] stringArray = { "apple", "banana", "cherry" };
Copy after login

6, Ruby:

string_array = ["apple", "banana", "cherry"]
Copy after login
Copy after login

7. Go:

The string array in Go language is as follows:

var stringArray = []string{"apple", "banana", "cherry"}
Copy after login

The above is the detailed content of What are the methods of assigning values ​​to string arrays?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!