将字符串转long[], 例如 将 "1234" 转成 [1, 2, 3, 4], String str12 = "1234";用stream流如何写
时间: 2023-06-06 09:07:31 浏览: 106
?
可以用以下代码将字符串转为long数组:
String str12 = "1234";
long[] longArray12 = str12.chars()
.mapToLong(Character::getNumericValue)
.toArray();
相关问题
vue string字符串转long数组
在Vue中,如果你想将一个字符串转换为长整型数组,你可以使用JavaScript的split方法和Vue实例的方法来实现。你可以将字符串用逗号分隔符进行分割,然后使用JavaScript的map方法将每个字符串转换为长整型。下面是一个示例代码:
```javascript
// Vue实例中的方法
methods: {
stringToLongArray(str) {
return str.split(',').map(Number);
}
}
```
然后,你可以在Vue模板中调用这个方法,传入你想要转换的字符串作为参数:
```html
<template>
<div>
<button @click="convertString">转换字符串</button>
</div>
</template>
<script>
export default {
data() {
return {
str: '1,2,3,4,5' // 你想要转换的字符串
};
},
methods: {
convertString() {
const longArray = this.stringToLongArray(this.str);
console.log(longArray); // 输出转换后的长整型数组
}
}
};
</script>
```
通过调用`stringToLongArray`方法并传入你想要转换的字符串,你可以将字符串转换为长整型数组并在控制台中打印出来。
用java将Long类型的ruleId和packageId转换成字符串拼接到一起
您可以使用加号运算符将Long类型的ruleId和packageId转换成字符串并拼接在一起。示例如下:
```
Long ruleId = 123456789L;
Long packageId = 987654321L;
String str = ruleId.toString() + packageId.toString();
```
或者使用String类的concat()方法:
```
Long ruleId = 123456789L;
Long packageId = 987654321L;
String str = ruleId.toString().concat(packageId.toString());
```
这两种方法都可以将Long类型的ruleId和packageId转换为字符串类型并拼接在一起。
阅读全文
相关推荐
















