简单东西-String的format

来源:互联网 发布:mac桌面保护程序闪退 编辑:程序博客网 时间:2024/05/21 06:50

        Java的String类的静态方法format可以完成对字符串的格式化,在web应用中替换请求路径中的参数信息时可以使用

这个简单的函数。

       使用format比我以前用String的replace来替换参数,高明多了。

       简单代码如下:

public class StringTest {public static void main(String[] args) {String requestPath = "http://localhost:8080/mini_web/user=%s&password=%s";requestPath = String.format(requestPath, "wang","****");System.out.println("requestPath :"+requestPath);}}

测试结果:

requestPath :http://localhost:8080/mini_web/user=wang&password=****


0 0
原创粉丝点击