Java代码小片段(一)

目录

1.背景

2.环境

3.片段

1)片段一:首字母大写

2)片段二:字符替换

3)片段三:比较两个List去掉不存在的期望值

4)片段四:去掉指定位置的字符

5)片段五:list在指定位置插入元素的问题

6)centos下查看Java安装路径

4.参考资料


1.背景

记录一些日常中用到的Java代码的小片段

2.环境

Win7 + jdk1.8

3.片段

1)片段一:首字母大写

   public static String captureName(String name) {
        char[] cs=name.toCharArray();
        cs[0]-=32;
        return String.valueOf(cs);       // 仅返回首字母
   }

2)片段二:字符替换

// 去掉下面字符串中所有的.

String str = "123456-cirrors-0.1.2-x86_64-disk.img";

String bb = "\\.";      // 要替换的字符

String aa = "";         // 替换后的字符

String newStr = str.replaceAll(bb, aa);

3)片段三:比较两个List去掉不存在的期望值

ArrayList<String> actualList = new ArrayList<>();
actualList.add("1");
actualList.add("2");
actualList.add("3");

ArrayList<String> expectList = new ArrayList<>();
expectList.add("1");
expectList.add("5");
expectList.add("6");

containsList(actualList, expectList );

static Boolean containsList(ArrayList<String> actualList, ArrayList<String> expectList){
    if(actualList.containsAll(expectList)){
        return true;
    }  else {
        ArrayList<String> actualListBackUp = actualList;
        expectList.removeAll(actualList);
        System.out.println(,"This data is not in list  " + expectList);
        return false;
    }

   return true;
}

4)片段四:去掉指定位置的字符

String temp = tempIp.substring(0, tempIp.lastIndexOf(","));      // 去掉字符串最末位的字符

5)片段五:list在指定位置插入元素的问题

https://www.cnblogs.com/sxdcgaq8080/p/9779375.html

6)centos下查看Java安装路径

$ which java
/bin/java

$ ls -lrt /bin/java
/bin/java -> /etc/alternatives/java

$ ls -lrt /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64/jre/bin/java

4.参考资料

https://www.cnblogs.com/mr-wuxiansheng/p/7768491.html -- 根据map中某个key值排序

https://blog.csdn.net/gnail_oug/article/details/80324120 -- springboot上传文件时配置大小限制1

https://blog.csdn.net/tjcyjd/article/details/6804690 -- springboot上传文件时配置大小限制2

https://blog.csdn.net/weixin_42290280/article/details/82591161 -- Java之StringUtils的常用方法

https://blog.csdn.net/m178643/article/details/104172622 -- RestTemplate 发送https请求

https://www.cnblogs.com/zhengxl5566/p/11976361.html -- java枚举类型

https://blog.csdn.net/qq_36639124/article/details/84959186 -- java JsonArray中添加json数据

https://blog.csdn.net/qq_36838191/article/details/84382704 -- HttpEntity的类型及其使用

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值