首页
/
每日頭條
/
科技
/
ios數組轉字符串方法
ios數組轉字符串方法
更新时间:2026-08-16 21:27:06

ios數組轉字符串方法?1.将集合轉成String字符串2.将數組轉成String字符串,今天小編就來說說關于ios數組轉字符串方法?下面更多詳細答案一起來看看吧!

ios數組轉字符串方法(string字符串轉數組的方法)1

ios數組轉字符串方法

1.将集合轉成String字符串

String s=";for (int i = 0; i < numList.size; i++) {    if (s==") {	s=numList.get(i);    }else {	s=s+","+numList.get(i);    }}

List<String> numList=new ArrayList<String>;for(int i=1; i<10; i++){   numList.add(String.valueOf(i));     }

  • 定義 String s=” ” 用來循環存放從 numList 中遍曆出的值。
  • 輸出結果(字符中間加“,”)如:s=,1,2,3,4,5,6,7,8,9
  • 輸出結果(字符中間無間隔)如:s=123456789
  • String.valueOf 該方法可以将非 String 類型數值轉換成 String 類型數值。

2.将數組轉成String字符串

String  arr = {"abc", "123", "@#&"};	StringBuffer sb = new StringBuffer;	for(int i = 0; i < arr.length; i++){	sb. append(arr[i]);	}	String ns = sb.toString;		System.out.println(ns);		}

  • 運行後顯示結果如:abc123@#&
  • 使用 String.valueOf 該方法可以将非 String 類型數值轉換成 String 類型數值,int類型數組同樣可用。例:sb.append(String.valueOf(arr[i]));
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2026 - www.tftnews.com All Rights Reserved