一周工作总结

1、Idea使用时无故自动关闭或者被迫强制结束进程,导致已开启的服务器未能断开连接,占用端口号,导致再启动服务时显示端口号被占用。

解:打开cmd窗口执行 netstat -ano | findstr 被占用的端口号,得到Pid;

然后执行taskkill /f /t /im可杀死该程序,使被占用端口解放。

2.String.format的使用。(仅列举常用的)

%s,%S占位一个字符串
%c,%C占位一个字符

%s 占位一个字符串格式,若后者为对象类型则会调用后者的toString()方法,若本身为基本类型如int,则会自动装箱之后再执行toString方法。 

%S 会在%s的基础上将字符串所有字母大写

public static void main(String[] args) {
        String res = String.format("%s", "Hello World");
        System.out.println(res);
        String res2 = String.format("%S", "Hello World");
        System.out.println(res2);
    }


输出结果:
Hello World
HELLO WORLD

//---------------------------华丽分割线----------------------------------

 public static void main(String[] args) {
        int r=12;
        String res = String.format("%s", new Person(12,"张Xx"));
        System.out.println(res);
        String res2 = String.format("%S", new Person(12,"张Xx"));
        System.out.println(res2);
    }

输出结果:
Person{id=12, name='张Xx'}
PERSON{ID=12, NAME='张XX'}

//---------------------------华丽分割线----------------------------------

 %s可结合$符号使用,表示使用参数列表的第几个参数,示例如下图:

注:若使用了比如%3$s,但是没有对应的第三个参数,会报错。


public static void main(String[] args) {
        String res = String.format("%1$s", 12);
        System.out.println(res);
        String res2 = String.format("%2$S,%2$S,%1$s", new Person(12,"张Xx"),12);
        System.out.println(res2);
    }

输出结果:
12
12,12,Person{id=12, name='张Xx'}

还可在s前加上数字和-格式化输出,如:

private static void TestSs() {
        int r=12;
        String res = String.format("%8S,HelloWorld", 12);
        System.out.println(res);
        String res2 = String.format("%-8S,HelloWorld", 12);
        System.out.println(res2);
    }

输出结果:
      12,HelloWorld
12      ,HelloWorld

%c 占位一个字符可使用一般的char类型,也会自动将数字转为对应的字符,可占位中文字符。不可占位小数,但是(char)97.99F强制类型转换可以正常显示a。。。

public static void main(String[] args) {
        String res = String.format("%c", '你');
        System.out.println(res);
        String res2 = String.format("%c", 97);
        System.out.println(res2);
        String res3 = String.format("%C", 98);
        System.out.println(res3);
    }

输出结果:
你
a
B

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值