Java Integer如何获取第一位和最后一位,并截取
作者:通尼渣渣 时间:2022-12-27 08:27:13
Integer获取第一位和最后一位并截取
场景
获取 5,10,15,25,30; 判断尾数为5的进入判断
public static void main(String[] args) {
String str = "数据测试,自定义字段";
//判断第一个字符是否为“数”
if (str.startsWith("数")) {
str = str.substring(1);
}
//判断最后一个字符是否为“段”
if (str.endsWith("段")) {
str = str.substring(0,str.length() - 1);
}
System.out.println(str);
}
求Integer位数的巧妙方法
今天看java源码发现的,挺有趣。
final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
99999999, 999999999, Integer.MAX_VALUE };
// Requires positive x
static int stringSize(int x) {
for (int i=0; ; i++)
if (x <= sizeTable[i])
return i+1;
}
来源:https://blog.csdn.net/plqaxx/article/details/108851856
标签:Java,Integer,第一位,最后一位,截取
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SpringBoot使用过滤器、拦截器和监听器的案例代码(Springboot搭建java项目)
2022-11-21 06:08:54
Java连接ftp服务器实例代码
2022-04-26 23:12:37
SpringBoot参数校验与国际化使用教程
2021-11-13 15:52:21
![](https://img.aspxhome.com/file/2023/8/61568_0s.png)
C#实现单例模式的几种方法总结
2023-10-13 16:33:55
两路归并的数组与链表的实现方法
2021-10-28 04:32:15
使用监听器对Spring bean id进行唯一校验过程解析
2022-04-12 18:07:21
30条Java代码编写经验分享
2022-01-09 06:41:42
Android源码系列之深入理解ImageView的ScaleType属性
2022-12-14 07:51:59
![](https://img.aspxhome.com/file/2023/7/128987_0s.png)
详解elasticsearch实现基于拼音搜索
2022-12-06 04:23:04
![](https://img.aspxhome.com/file/2023/9/82049_0s.png)
Android UI使用HTML布局方法实例
2023-04-07 09:14:11
c# 代码调试技巧和如何远程调试
2022-09-26 14:11:19
![](https://img.aspxhome.com/file/2023/7/87017_0s.png)
一文搞懂Java设计模式之责任链模式
2021-12-24 22:19:40
![](https://img.aspxhome.com/file/2023/4/132064_0s.png)
并行Stream与Spring事务相遇会发生什么?
2022-08-28 15:40:12
![](https://img.aspxhome.com/file/2023/4/85944_0s.webp)
Spring Boot缓存实战 EhCache示例
2023-08-30 12:23:35
![](https://img.aspxhome.com/file/2023/3/58213_0s.png)
IDEA部署JavaWeb项目到Tomcat服务器的方法
2023-11-02 23:21:22
java实现最短路径算法之Dijkstra算法
2021-12-28 12:26:06
![](https://img.aspxhome.com/file/2023/3/97973_0s.png)
java 创建线程的四种方式
2023-11-02 21:38:07
Qt QTableWidget基本操作及使用
2022-05-22 23:15:55
![](https://img.aspxhome.com/file/2023/5/117775_0s.gif)
Freemarker如何生成树形导航菜单(递归)
2023-02-24 13:52:16
Android IdleHandler使用方法详解
2023-11-17 20:48:11