StringUtils 工具

article/2025/10/16 0:54:52
		<dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId></dependency>

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
实验室:
常用方法:

        StringUtils.truncate("abcdefg", 7);StringUtils.wrapIfMissing("ab", 'x');StringUtils.remove("queued", "ue");StringUtils.replace("aba", "a", "");StringUtils.lastIndexOf("sdfafvdsffs", "v");StringUtils.appendIfMissing("sdsf","dfsf");StringUtils.substring("abc", 2);StringUtils.overlay("abcdef", "zzzz", -1, 4);StringUtils.equals("abc", "ABC");

全量的:

        String abl = "1,2,3,4,5,6";        // 11String abStr = "axcvabnmlKjhduweiu";// 17String abLagu = "犯我中华者";String abln = "\n";// abbreviate = ax...System.out.println("abbreviate = " + StringUtils.abbreviate(abStr,5));//  abbreviate2 = ...nmlk...System.out.println("abbreviate2 = " + StringUtils.abbreviate(abStr,5,10));//  abbreviate3 = axcvbnm***System.out.println("abbreviate3 = " + StringUtils.abbreviate(abStr, "***", 2, 10));// 中间替换符    abbreviateMiddle = axc***eiuSystem.out.println("abbreviateMiddle = " + StringUtils.abbreviateMiddle(abStr, "***", 9));// 字符串尾部加指定字符   appendIfMissingIgnoreCase() = axcvbnmlkjhduweiukSystem.out.println("appendIfMissingIgnoreCase() = " + StringUtils.appendIfMissingIgnoreCase(abStr,"k"));//  appendIfMissing = 1,2,3,4,5,6,7System.out.println("appendIfMissing = " + StringUtils.appendIfMissing(abl,",7","5"));// appendIfMissing = 犯我中华者,虽远必诛System.out.println("appendIfMissing = " + StringUtils.appendIfMissing(abLagu,",虽远必诛","华"));//  appendIfMissingIgnoreCase = 犯我中华者,虽远必诛System.out.println("appendIfMissingIgnoreCase = " + StringUtils.appendIfMissingIgnoreCase(abLagu, ",虽远必诛", "华"));// 首字母达成大写System.out.println("capitalize = " + StringUtils.capitalize(abStr));// center =   犯我中华者System.out.println("center = " + StringUtils.center(abLagu,10));//  center = axcvbnmlkjhduweiuSystem.out.println("center = " + StringUtils.center(abStr,3,"shiyi"));// 去除换行符System.out.println("chomp = " + StringUtils.chomp(abln));// 比较大小System.out.println("compare = " + StringUtils.compare("10","11"));// 比较大小  换算之后比System.out.println("compare = " + StringUtils.compare(abStr,abLagu));//  忽略大小写比较System.out.println("compareIgnoreCase = " + StringUtils.compareIgnoreCase("abc","Abc"));// 是否考虑值为null的时候System.out.println("compareIgnoreCasenull = " + StringUtils.compareIgnoreCase("abc","null",false));//  判断字符串是否包含abSystem.out.println("contains = " + StringUtils.contains(abStr,"ab"));// 任意包含System.out.println("containsAny = " + StringUtils.containsAny(abStr,"ab","b"));//  忽略大小写匹配System.out.println("containsIgnoreCase = " + StringUtils.containsIgnoreCase(abStr,"k"));// s在字符串中没有System.out.println("containsNone = " + StringUtils.containsNone(abStr,"s"));//System.out.println("containsOnly = " + StringUtils.containsOnly(abStr,"as"));// 检查是否有空字符 containsWhitespace = trueSystem.out.println("containsWhitespace = " + StringUtils.containsWhitespace("sfds dsf s"));//  a 在字符串中出现的次数    countMatches = 2System.out.println("countMatches = " + StringUtils.countMatches(abStr,"a"));// 空字符串替换成null  defaultString = nullSystem.out.println("defaultString = " + StringUtils.defaultIfBlank("","null"));// 空字符串替换成null  defaultIfEmpty = nullSystem.out.println("defaultIfEmpty = " + StringUtils.defaultIfEmpty("", "null"));// defaultString = zheshikongSystem.out.println("defaultString = " + StringUtils.defaultString(null,"zheshikong"));//  删除空字符串  deleteWhitespace = adfddSystem.out.println("deleteWhitespace = " + StringUtils.deleteWhitespace("a dfd d "));//  difference = xyzSystem.out.println("difference = " + StringUtils.difference("ab", "abxyz"));//  endsWith = trueSystem.out.println("endsWith = " + StringUtils.endsWith("abcdef", "def"));//  equals = falseSystem.out.println("equals = " + StringUtils.equals("abc", "ABC"));// firstNonBlank = xyzSystem.out.println("firstNonBlank = " + StringUtils.firstNonBlank(null, "", " ", "xyz"));//  getBytes = 18System.out.println("getBytes = " + StringUtils.getBytes(abStr, "utf-8").length);//  getCommonPrefix = abSystem.out.println("getCommonPrefix = " + StringUtils.getCommonPrefix(new String[]{"abcde", "ab"}));//  getDigits = 5417543010System.out.println("getDigits = " + StringUtils.getDigits("(541) 754-3010"));// getFuzzyDistance = 2System.out.println("getFuzzyDistance = " + StringUtils.getFuzzyDistance("Workshop", "ws", Locale.ENGLISH));// getIfBlank = nullSystem.out.println("getIfBlank = " + StringUtils.getIfBlank("", () -> null));// 字符串相似度       getJaroWinklerDistance = 0.88System.out.println("getJaroWinklerDistance = " + StringUtils.getJaroWinklerDistance("hello", "hallo"));//  getLevenshteinDistance = 7System.out.println("getLevenshteinDistance = " + StringUtils.getLevenshteinDistance("elephant", "hippo", 7));// indexOf = 2System.out.println("indexOf = " + StringUtils.indexOf("aabaabaa", "b"));//  indexOfAny = 3System.out.println("indexOfAny = " + StringUtils.indexOfAny("zzabyycdxx", new String[]{"b", "y"}));// indexOfAnyBut = 0System.out.println("indexOfAnyBut = " + StringUtils.indexOfAnyBut("aba", new char[] {'z'} ) );// indexOfDifference = -1System.out.println("indexOfDifference = " + StringUtils.indexOfDifference(new String[]{"abc", "abc"}));//  isAllBlank = falseSystem.out.println("isAllBlank = " + StringUtils.isAllBlank(" ", "bar") );// isAllLowerCase = falseSystem.out.println("isAllLowerCase = " + StringUtils.isAllLowerCase("ab1c"));//  isAllUpperCase = trueSystem.out.println("isAllUpperCase = " + StringUtils.isAllUpperCase("ABC") );// 检查 CharSequence 是否仅包含 Unicode 字母 isAlpha = trueSystem.out.println("isAlpha = " + StringUtils.isAlpha("abc"));//  isMixedCase = trueSystem.out.println("isMixedCase = " + StringUtils.isMixedCase("a/C"));// isNotBlank = falseSystem.out.println("isNotBlank = " + StringUtils.isNotBlank(" "));//  isNotEmpty = trueSystem.out.println("isNotEmpty = " + StringUtils.isNotEmpty(" "));//  isNumeric = falseSystem.out.println("isNumeric = " + StringUtils.isNumeric("12-3"));//  join = 1;2;3System.out.println("join = " + StringUtils.join(Arrays.asList(1, 2, 3),";"));//  lastIndexOf = 5System.out.println("lastIndexOf = " + StringUtils.lastIndexOf("sdfafvdsffs","v"));// left = abcSystem.out.println("left = " + StringUtils.left("abc", 4));//  leftPad =**batSystem.out.println("leftPad = " + StringUtils.leftPad("bat", 5,"**"));// length = 6System.out.println("length = " + StringUtils.length("sdfdfs"));//  mid = cSystem.out.println("mid = " + StringUtils.mid("abc", 2, 4));//  不知道System.out.println("abln = " + StringUtils.normalizeSpace("sdfs dsfs"));//  ordinalIndexOf = 4System.out.println("ordinalIndexOf = " + StringUtils.ordinalIndexOf("aabaabaa", "ab", 2));//  overlay = zzzzefSystem.out.println("overlay = " + StringUtils.overlay("abcdef", "zzzz", -1, 4));//  prependIfMissing = xyzMNOabcSystem.out.println("prependIfMissing = " + StringUtils.prependIfMissing("MNOabc", "xyz", "mno"));//  remove = qdSystem.out.println("remove = " + StringUtils.remove("queued", "ue"));//  repeat = ababSystem.out.println("repeat = " + StringUtils.repeat("ab", 2));//  replace = bSystem.out.println("replace = " + StringUtils.replace("aba", "a", ""));System.out.println("replace = " + StringUtils.replace("我给他批量添加了标签", "批量添加", "#"));//  replaceAll = ABC_123System.out.println("replaceAll = " + StringUtils.replaceAll("ABCabc123", "[^A-Z0-9]+", "_"));//  replaceChars = aycyaSystem.out.println("replaceChars = " + StringUtils.replaceChars("abcba", 'b', 'y'));//  reverse = tabSystem.out.println("reverse = " + StringUtils.reverse("bat"));//  reverseDelimited = c.b.aSystem.out.println("reverseDelimited = " + StringUtils.reverseDelimited("a.b.c", '.'));//  split = {abc,def}String[] split = StringUtils.split("abc  def");System.out.println("split = " + ArrayUtils.toString(split));//  substring = cSystem.out.println("substring = " + StringUtils.substring("abc", 2));//  swapCase = tHE DOG HAS A boneSystem.out.println("swapCase = " + StringUtils.swapCase("The dog has a BONE"));//  trim = abcSystem.out.println("trim = " + StringUtils.trim("    abc    "));//  truncate = abcdefgSystem.out.println("truncate = " + StringUtils.truncate("abcdefg", 7));//  wrapIfMissing = xabxSystem.out.println("wrapIfMissing = " + StringUtils.wrapIfMissing("ab", 'x'));

能看到这里,说明你多少有点无聊,划水摸鱼第一名就是你!!!


http://chatgpt.dhexx.cn/article/n5VEQyK5.shtml

相关文章

StringUtils

今天我来谈一下Java里面一个工具类StringUtils&#xff0c;其实在Java里面一般把工具类写成静态的&#xff0c;这样是为了在使用的时候好调用。但是StringUtils这个类在Java API文档是没有的&#xff0c;所以必须要去倒StringUtils所属于的jar包。而StringUtils所属于的jar包是…

使用Python websockets搭建互联网服务器

在上一篇文章中实现局域网的通信&#xff0c;使用websockets,python作服务端&#xff0c;unity作客服端完成网络通信 这次准备实现互联网上的通信。 1.整个云服务器 要实现互联网通信&#xff0c;简单的方法就是先准备一个云服务器&#xff0c;这里我直接使用了阿里云服务器。…

【ZED2-3】python同时实现websockets与flask

上篇博客【ZED-2】基于WebSockets库&#xff0c;通过多线程方式推送数据流_WXG1011的博客-CSDN博客采用多线程方式&#xff0c;基于websockets库实现数据流的推送&#xff0c;这篇博客主要实现将前端&#xff08;nx板&#xff09;代码移植到flask框架中&#xff0c;通过http方式…

【burpsuite安全练兵场-客户端16】测试WebSockets安全漏洞-3个实验(全)

前言&#xff1a; 介绍&#xff1a; 博主&#xff1a;网络安全领域狂热爱好者&#xff08;承诺在CSDN永久无偿分享文章&#xff09;。 殊荣&#xff1a;CSDN网络安全领域优质创作者&#xff0c;2022年双十一业务安全保卫战-某厂第一名&#xff0c;某厂特邀数字业务安全研究员&…

在python中使用websockets

WebSocket (WebSocket) Websocket is a communications protocol, providing full-duplex bi-directional communication over a single TCP connection. Websocket是一种通信协议,可通过单个TCP连接提供全双工双向通信。 To understand Websockets, first, we have to have …

django3 websockets

一、概述 现在Django 3.0附带了对ASGI的支持&#xff0c;将Websockets添加到Django应用中不需要任何额外的依赖关系。 在本文中&#xff0c;您将学习如何通过扩展默认的ASGI应用程序来使用Django处理Websocket。 我们将介绍如何在示例ASGI应用程序中处理Websocket连接&#xff…

websockets_WebSockets简介

websockets WebSockets are an alternative to HTTP communication in Web Applications. WebSocket是Web应用程序中HTTP通信的替代方法。 They offer a long lived, bidirectional communication channel between client and server. 它们在客户端和服务器之间提供了长期的双…

尝试Python的websockets库的最基础功能

目标 尝试最简单的代码创建一个服务器并在客户端收发信息。 主要参考的是官方文档的首页&#xff1a;https://websockets.readthedocs.io/ &#xff08;还需要 asyncio 库的一些知识&#xff0c;可见之前的博客 翻译《使用asyncio的一个指南》作者&#xff1a;Andrew Crozier…

python使用websockets库

python使用websockets库 serve:在server端使用&#xff0c;等待客户端的连接。如果连接成功&#xff0c;返回一个websocket。 connect: 在client端使用&#xff0c;用于建立连接。 send:发送数据 recv:接收数据 close:关闭连接 服务端 #!/usr/bin/python3 # 主要功能&am…

什么是WebSockets!?

到目前为止&#xff0c;我们已经深入到实时世界&#xff0c;因为许多应用程序使用实时数据。 现在正是以技术立场解释所有导致这一点的事件的时候了。 所以&#xff0c;这里...... 目前&#xff0c;应用程序正在从利用数据库中的陈旧数据或在实际事件之后的实时体验中事…

WebSockets介绍

Web sockets定义为在servers和clients之间的双向连接。意味着servers和clients可以同时交流并发送数据。这种协议是从底层就是双工连接。Web sockets技术上得到了质的飞跃。 握手是一个过程&#xff0c;确保server与client同步。握手是Web Socket protocol的基础概念。 下面的图…

websockets_将WebSockets与Node.js结合使用

websockets WebSockets are an alternative to HTTP communication in Web Applications. WebSocket是Web应用程序中HTTP通信的替代方法。 They offer a long lived, bidirectional communication channel between client and server. 它们在客户端和服务器之间提供了长期的双…

各大公司数据结构与算法面试题解答(一)

还有一年就要找工作了&#xff0c;从现在开始找些公司的数据结构和算法的题来做一做&#xff0c;不定时贴出笔试面试题代码。 1.创新工场&#xff1a; 求一个数组的最长递减子序列比如{9&#xff0c;4&#xff0c;3&#xff0c;2&#xff0c;5&#xff0c;4&#xff0c;3&…

数据结构面试题整理

一 数据结构 1.你熟悉什么数据结构&#xff1f; 数组 链表 栈 队列 哈希 二叉树 二叉查找树 二叉堆 b树 b树 2.b树 b树 b*树 b和b都是节点可以有很多子节点&#xff0c;区别是b树所有的节点都可以存储关键字&#xff0c;而b树只有叶子节点存储关键字&#xff0c;适用于数据库…

数据结构与算法三十题,弄懂这些面试就够了!

https://www.toutiao.com/a6649963989537128967/ 2019-01-24 15:36:35 国外 IT 教育学院 Educative.io 创始人 Fahim ul Haq 写过一篇过万赞的文章《The top data structures you should know for your next coding interview》,总结了程序员面试中需要掌握的 8 种数据结构知识…

数据结构与算法面试知识点汇总(超全)

文章目录 一、哈希函数和哈希表01 哈希函数02 哈希表 二、布隆过滤器三、一致性哈希四、并查集01 具体实现02 优化03 代码实现 五、前缀树&#xff08;trie树&#xff09;六、B树和B树七、线段树01 线段树的优势02 线段树实现 一、哈希函数和哈希表 01 哈希函数 哈希函数&…

《数据结构》十道链表经典面试题多种方法深度解析

目录 ⛰️一、题目解析 &#x1f5fb;1.1删除链表中等于给定值 val 的所有节点&#xff08;力扣&#xff09; &#x1f5fb;1.2反转一个单链表。&#xff08;力扣&#xff09; &#x1f5fb;1.3给定一个带有头结点 head 的非空单链表&#xff0c;返回链表的中间结点。如果有…

数据结构和算法常见面试问题总结,含答案

0. 写在前面 总导航在此 这些问题是我备考数据结构和算法的过程中&#xff0c;详细总结的常见面试问题和答案。逐个搜索并记录下来&#xff0c;花了很大的精力&#xff01;如果想要获取源文件的话&#xff0c;可以关注我的微信公众号&#xff1a;小梁说代码&#xff0c;获取嘿…

(六)数据结构面试必问

什么是链表、队列、栈&#xff1f; 链表&#xff1a; 当需要存储多个相同数据类型的时候&#xff0c;可以使用数组存储&#xff0c;数组可以通过下标直接访问&#xff0c;但数组有个缺点就是无法动态的插入或删除其中的元素&#xff08;特别是操作第一个位置上的元素&#xff…

数据结构常见面试题

链表是最基本的数据结构&#xff0c;面试官也常常用链表来考察面试者的基本能力&#xff0c;而且链表相关的操作相对而言比较简单&#xff0c;也适合考察写代码的能力。链表的操作也离不开指针&#xff0c;指针又很容易导致出错。综合多方面的原因&#xff0c;链表题目在面试中…