Java_String Format

public static void main(String[] args) {
	String URL = "http://www.baidu/api/v1/posts/%1$s.json?page=%2$d&token=%3$s";
	System.out.println(String.format(URL, "info", 11, "sdadasdasd3213213"));

	//http://www.baidu/api/v1/posts/info.json?page=11&token=sdadasdasd3213213
}

String.format是在JDK1.5中新增的静态方法,它主要功能是格式化数据,大致分为这些类(常规类型、字符类型、数值类型、日期类型)。

它的语法如下: 常规类型、字符类型和数值类型的格式说明符的语法:%[参数索引位置$][转换标识符][最小官渡][.保留精度位数]转换方式,1$, 2$代表参数索引位置,而d, s则是转换标示符,关于更多的转换标示符见下面:

%s 字符串类型 如"name"

%c 字符类型 ‘m’

%b 布尔类型 true

%d 整数类型(十进制) 99

%x 整数类型(十六进制) FF

%o 整数类型(八进制) 77

%f 浮点类型 99.99

%a 十六进制浮点类型 FF.35AE

%e 指数类型 9.38e+5

%g 通用浮点类型(f和e类型中较短的)

%% 百分比类型 %

%n 换行符

%tx 日期与时间类型(x代表不同的日期与时间转换符)

时间: 2024-08-03 15:22:47

Java_String Format的相关文章

category is in invalid format hint微信第三方平台将第三方提交的代码包提交审核出错

微信第三方平台通过接口https://api.weixin.qq.com/wxa/submit_audit?access_token=TOKEN将第三方提交的代码包提交审核时一直返回错误码85008的错误信息: category is in invalid format hint 查了半天是接口提交数据时json_encode时中文不能编码提交 将向微信的提交代码     $this->https_post($url,json_encode($postData)); 改为     $this->

clang format 官方文档自定义参数介绍(中英文)

英文 Configuring Style in Code When using clang::format::reformat(...) functions, the format is specified by supplying the clang::format::FormatStyle structure. Configurable Format Style Options This section lists the supported style options. Value typ

我的Android进阶之旅------>Java字符串格式化方法String.format()格式化float型时小数点变成逗号问题

今天接到一个波兰的客户说有个APP在英文状态下一切运行正常,但是当系统语言切换到波兰语言的时候,程序奔溃了.好吧,又是我来维护. 好吧,先把系统语言切换到波兰语,切换到波兰语的方法查看文章 我的Android进阶之旅------>Android[设置]-[语言和输入法]-[语言]列表中找到相应语言所对应的列表项 地址:http://blog.csdn.net/ouyang_peng/article/details/50209789 ================================

delphi中的Format函数详解

首先看它的声明:[[email protected]][@21ki!] function Format(const Format: string; const Args: array of const): string; overload;[[email protected]][@21ki!] 事实上Format方法有两种形式,另外一种是三个参数的,主要区别在于它是线程安全的,[[email protected]][@21ki!]但并不多用,所以这里只对第一个介绍:[[email protect

pip 警告!The default format will switch to columns in the future

pip警告! DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning. pip升级到9.0.1后 查看pip.list 出现的警告

加压压缩文件报错gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now

压缩包是直接weget 后面加官网上的tar包地址获取的 [[email protected] ~]# tar -zxvf /home/hadoop/hadoop-2.6.5-src.tar.gz gzip: stdin: not in gzip formattar: Child returned status 1tar: Error is not recoverable: exiting now[[email protected] ~]# tar -xvf /home/hadoop/hadoo

%和str.format

%  符   号  描述       %s  格式化字符串       %d  格式化整数       %f  格式化浮点数字,可指定小数点后的精度       %c  格式化字符及其ASCII码       %u  格式化无符号整型       %o  格式化无符号八进制数       %x  格式化无符号十六进制数       %X  格式化无符号十六进制数(大写)       %e  用科学计数法格式化浮点数       %E  作用同%e,用科学计数法格式化浮点数       %g  %

【java】Date与String之间的转换:java.text.SimpleDateFormat、public Date parse(String source) throws ParseException和public final String format(Date date)

1 package 日期日历类; 2 3 import java.text.ParseException; 4 import java.text.SimpleDateFormat; 5 import java.util.Date; 6 7 public class TestDate { 8 public static void main(String[] args) { 9 Date date=new java.util.Date(); 10 System.out.println(date);/

R语言入门视频笔记--6--R函数之cat、format、switch函数

一.cat 猫  怎么就变成一个输出函数了呢? cat  一个输出函数,功能和print有相同之处 我们一起比较看看 1.cat("hellow world")或cat('hellow world')输出的是: hello world 1 print("hellow world")或print('hellow world')输出的是: [1] "hello world 1 " 2.cat(c("AB","C"