java用for循环将字符串数组用concat方法拼接成字符串
时间: 2024-05-03 09:21:59 浏览: 12
可以使用以下代码:
```java
String[] strArr = {"Hello", "World", "!"};
String result = "";
for (int i = 0; i < strArr.length; i++) {
result = result.concat(strArr[i]);
}
System.out.println(result);
```
输出结果为:
```
HelloWorld!
```
相关问题
unity将三个字符串数组添加至一个字符串数组中
可以使用Concat方法将三个字符串数组添加至一个字符串数组中。
示例代码如下:
```
string[] arr1 = {"hello", "world"};
string[] arr2 = {"good", "morning"};
string[] arr3 = {"nice", "to", "meet", "you"};
string[] result = arr1.Concat(arr2).Concat(arr3).ToArray();
foreach (string str in result)
{
Console.WriteLine(str);
}
```
输出结果为:
```
hello
world
good
morning
nice
to
meet
you
```
C#字符串数组连接字符串数组
可以使用C#的Concat方法来连接两个字符串数组。示例代码如下:
```csharp
string[] array1 = {"hello", "world"};
string[] array2 = {"how", "are", "you"};
string[] result = array1.Concat(array2).ToArray();
string concatenatedString = string.Join(" ", result);
Console.WriteLine(concatenatedString);
```
输出结果为:hello world how are you