Home >Common Problem >What are the methods of assigning values ​​to string arrays?

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

小老鼠
小老鼠Original
2023-12-25 17:07:172106browse

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"]

2, Java:

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

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

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

3. C :

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

Or use C-style string array:

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

4, JavaScript:

let stringArray = ["apple", "banana", "cherry"];

5, C#:

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

6, Ruby:

string_array = ["apple", "banana", "cherry"]

7. Go:

The string array in Go language is as follows:

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

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!

Statement:
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