「数组拼接java」数组拼接js
本篇文章给大家谈谈数组拼接java,以及数组拼接js对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、Java数组拼接字符串?
- 2、Java怎么实现两个数组的拼接
- 3、JAVA怎么合并两个数组
- 4、加解密时 key=value参数用&连接数组怎么拼JAVA
- 5、java 如何将split拆分的数组拼接成字符串
- 6、Java中如何把两个数组合并为一个
Java数组拼接字符串?
public class Test {
public static void main(String[] args){
String[] str={"a","b","c","d","e","f","g","h","i"};//定义字符串数组
method(str);
}
private static void method(String[] s){
if(s==null)
return;
StringBuffer sBuffer=new StringBuffer();
for(int i=0;is.length;i++){//将数组拼接成字符串
sBuffer.append(s[i]);
}
System.out.println("字符串长度:"+sBuffer.length());
System.out.println("拼接的字符串:"+sBuffer.toString());
}
}
Java怎么实现两个数组的拼接
我已经写完代码。
import java.util.ArrayList;
import java.util.List;
/**
*
* 开发公司:SOJSON在线工具
* 版权所有:©
* 博客地址:
* p
*
* 注释写这里
*
* p
*
* 区分 责任人 日期说明br/
* 创建 周柏成 2017年4月2日 br/
*
* @author zhou-baicheng
* @email so@sojson.com
* @version 1.0,2017年4月2日 br/
*
*/
public class Test {
public static void main(String[] args) {
//定义2个数组
int [] array1 = {1,2,3,4};
int [] array2 = {4,5,6,7};
//2个数组的长度
int length = array1.length + array2.length;
//开始合并
//定义好一个长度为array1 + array2的长度(可以给,可以不给)
ListInteger list = new ArrayListInteger(length);
for (int a : array1) {
list.add(a);
}
for (int a : array2) {
list.add(a);
}
//把List 转换成array【完成】
Integer[] newArray = list.toArray(new Integer[length]);
for (Integer element : newArray) {
//输出每一个元素
System.out.println(element);
}
}
}
JAVA怎么合并两个数组
三种字符数组合并的方法
public static String[] getOneArray() {
String[] a = { "0", "1", "2" };
String[] b = { "0", "1", "2" };
String[] c = new String[a.length + b.length];
for (int j = 0; j a.length; ++j) {
c[j] = a[j];
}
for (int j = 0; j b.length; ++j) {
c[a.length + j] = b[j];
}
return c;
}
public static Object[] getTwoArray() {
String[] a = { "0", "1", "2" };
String[] b = { "0", "1", "2" };
List aL = Arrays.asList(a);
List bL = Arrays.asList(b);
List resultList = new ArrayList();
resultList.addAll(aL);
resultList.addAll(bL);
Object[] result = resultList.toArray();
return result;
}
public static String[] getThreeArray() {
String[] a = { "0", "1", "2", "3" };
String[] b = { "4", "5", "6", "7", "8" };
String[] c = new String[a.length + b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);
return c;
}
Reference:
加解密时 key=value参数用&连接数组怎么拼JAVA
加解密时key=value参数用连接数组拼JAVA方式:
1.BASE64加密/解密,
2.MD5(MessageDigestAlgorithm)加密。
3.DES(DataEncryptionStandard)对称加密/解密。
java 如何将split拆分的数组拼接成字符串
public class Hello{
public static void main(String[] args){
String str = "a,b,c,d";
String[] arr = new String[str.replaceAll(",","").length()];
String result = "";
for(int i = 0; i arr.length; i++){
arr[i] = str.replaceAll(",","").substring(i,(i+1));
}
for(int i = 0; i arr.length; i++){
if(i == 0){
result += arr[i] + ",";
}else if(i == arr.length - 1){
result += arr[i];
}else{
result += "'" + arr[i] + "',";
}
}
System.out.println(result);
}
}
//运行结果:
a,'b','c',d
Java中如何把两个数组合并为一个
import java.util.Arrays;
//Java中如何把两个数组合并为一个
public class gog {
public static void main(String[] args) {
String [] str1 = {"J","a","v","a","中"};
String [] str2 = {"如","何","把","两","个","数","组","合","并","为","一","个"};
int strLen1=str1.length;//保存第一个数组长度
int strLen2=str2.length;//保存第二个数组长度
str1= Arrays.copyOf(str1,strLen1+ strLen2);//扩容
System.arraycopy(str2, 0, str1, strLen1,strLen2 );//将第二个数组与第一个数组合并
System.out.println(Arrays.toString(str1));//输出数组
}
}
关于数组拼接java和数组拼接js的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。