1、已知int[] arr = {34,12,89,68};

  将其中的元素转成字符串,格式 [34,12,89,68];

  参考:02011_定义打印数组元素方法,按照给定的格式打印[11, 33, 44, 22, 55]

 public class Test {
public static void main(String[] args) {
int[] arr = { 34, 12, 89, 68 };
System.out.println(toString_2(arr));
} public static String toString_2(int[] arr) {
StringBuffer sb = new StringBuffer();
sb.append("[");
for (int i = 0; i < arr.length; i++) {
if (i != arr.length - 1) {
sb.append(arr[i] + ",");
} else {
sb.append(arr[i] + "]");
}
}
return sb.toString();
} }

2、温馨提示:?    无论多少数据,数据是什么类型都不重要,只要最终变成字符串就可以使用StringBuffer这个容器。

  

1024x768

l  无论多少数据,数据是什么类型都不重要,只要最终变成字符串就可以使用StringBuffer这个容器

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Calibri","sans-serif";
mso-bidi-font-family:"Times New Roman";}

02018_StringBuffer练习的更多相关文章

随机推荐

  1. [Cypress] Load Data from Test Fixtures in Cypress

    When creating integration tests with Cypress, we’ll often want to stub network requests that respond ...

  2. sqlite3树形结构遍历效率对照測试

    sqlite3树形结构遍历效率对照測试 一.缘起 项目数据结构:本人从事安防行业,视频监控领域.项目中会遇到监控点位的组织机构划分.暂时划分的巡逻点位等.这些相机点位.连同组织机构,它们在逻辑关系上构 ...

  3. Linux 服务具体解释

    acpid ACPI(全 称 Advanced Configuration and Power Interface)服务是电源管理接口. 建议全部的笔记本用户开启它. 一些server可能不须要 ac ...

  4. 学习 java netty (一) -- java nio

    前言:近期在研究java netty这个网络框架,第一篇先介绍java的nio. java nio在jdk1.4引入,事实上也算比較早的了.主要引入非堵塞io和io多路复用.内部基于reactor模式 ...

  5. c26---文件包含include

    // // main.c // 文件包含 #include <stdio.h> // 函数可以重复声明, 但不能重复定义 void test(); void test(); void te ...

  6. c18---数组和指针

    // // main.c // day09 #include <stdio.h> int main(int argc, const char * argv[]) { ; int *numP ...

  7. 【NOIP 2004】 虫食算

    [题目链接] https://www.luogu.org/problemnew/show/P1092 [算法] 搜索 + 剪枝 直接搜索显然会超时,考虑剪枝 1 : 优化搜索顺序 2 : 假设我们已经 ...

  8. 根据日期获取,x岁x月x天

    c#: DateTime startDate = new DateTime(); DateTime endDate = new DateTime(); ; ; ; if (endDate.Month& ...

  9. hihoCoder-1633 ACM-ICPC北京赛区2017 G.Liaoning Ship’s Voyage 线段与三角形规范相交

    题面 题意:给你一个20*20的地图,起点(0,0),终点(n-1,n-1),有障碍的点为‘#’,每次可以向8个方向走一步,还给了一个三角形,除了障碍以外,到这8个方向上的点的线段如果没有与三角形相交 ...

  10. java+appium+安卓模拟器实现app自动化Demo

    网上有比较多相关教程,自己写一遍,加深下印象. 环境搭建 据说,很多人都被繁琐的环境搭建给吓到了. 是的,确实,繁琐. node.js 网址 cmd输入node -v,出现下图说明成功. JDK 网址 ...