public class TestN { public static void main(String[] args) { int[] a = {1,2,3,4,67,8}; StringBuilder test = new StringBuilder(); for(int i=0;i<a.length-1;i++) { test.append(a[i]+","); //前 n-1 个元素 } test.append(a[a.length-1]); //将最后一个元素单独加上,解决末尾有","问题 System.out.println(test); } }
public class ConnectString { public static void main(String[] args) { String result = new String(); if(args.length <= 0) { System.out.println( "Useage: java ConnectString int[]"); } else { for(int i = 0; i < args.length; i ++) { result += args[i]; if(i != args.length - 1) result += ","; } }
System.out.println(result); } }
public static void main( String[] args ) { int[] arr = { 1, 2, 3, 4, 5, 6, 2, 3, 33, 44 }; StringBuilder buf = new StringBuilder(); for ( int i = 0; i < arr.length - 1; i++ ) { buf.append( arr[i] + "," ); } buf.append( arr[arr.length - 1] ); System.out.println( buf ); }
public class cTest { /**
* @param args
*/
public static void main(String[] args) {
int[]a = new int[] {1,2,3};
int j = 0;
StringBuffer buf = new StringBuffer();
if (a.length > 0){
for ( j = 0 ; j < a.length-1 ; ++j){
buf.append(String.valueOf(a[j])+",");
}
buf.append(String.valueOf(a[j]));
}
System.out.print(buf.toString());
}
}
String s="";
for(int i:itr){
s+=","+i;
}
s=s.substring(1);
public class arrConn
{ public static void main(String[] args)
{
Integer[] array;
array = new Integer[] {1,2,3,4,5,6,7,8,9,0};
String str = "";
for (int i=0;i<array.length-1;i++)
{
str = str + array[i].toString() + ",";
}
str = str + array[array.length-1].toString();
System.out.println(str);
}
}
public class intToStr{
public static void main(String[] args)
{
int[] in={1,2,3}
Sring str=""
for(int i=0;i<in.length;i++)
if(str==""){
str= in[i].toString;
}else{
str=str+in[i].toString+",";
}
}
System.out.println(str); }
int[] itr={1,2,3}
String s="" + itr[0];
for(int i=1; i<itr.length; i++){
s += ","+itr[i];
}
System.out.println(s);
public class TestN
{
public static void main(String[] args)
{
int[] a = {1,2,3,4,67,8};
StringBuilder test = new StringBuilder();
for(int i=0;i<a.length-1;i++)
{
test.append(a[i]+","); //前 n-1 个元素
}
test.append(a[a.length-1]); //将最后一个元素单独加上,解决末尾有","问题
System.out.println(test);
}
}
public static void main(String[] args) { String result = new String();
if(args.length <= 0) {
System.out.println(
"Useage: java ConnectString int[]");
}
else {
for(int i = 0; i < args.length; i ++) {
result += args[i];
if(i != args.length - 1)
result += ",";
}
}
System.out.println(result);
}
}
{
int[] arr = { 1, 2, 3, 4, 5, 6, 2, 3, 33, 44 };
StringBuilder buf = new StringBuilder();
for ( int i = 0; i < arr.length - 1; i++ )
{
buf.append( arr[i] + "," );
}
buf.append( arr[arr.length - 1] );
System.out.println( buf );
}