String工具类转小写
时间: 2023-11-02 17:00:53 浏览: 58
要将字符串转为小写,可以使用String类的toLowerCase()方法。这个方法会返回一个新的字符串,其中所有的大写字符都会被转换为小写字符。
下面是一个示例代码:
```java
String str = "Hello World!";
String lowerStr = str.toLowerCase();
System.out.println(lowerStr); // 输出: hello world!
```
这里将字符串"Hello World!"转为小写,并将结果赋值给lowerStr变量。然后将lowerStr打印出来,结果是"hello world!"。
相关问题
java md5 32位小写加密工具类
以下是一个Java的MD5 32位小写加密工具类的示例代码,您可以根据自己的需求进行修改和使用:
```java
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
/**
* 对字符串进行MD5 32位小写加密
* @param str 待加密的字符串
* @return 加密后的字符串
*/
public static String md5(String str) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes());
byte[] b = md.digest();
int i;
StringBuilder buf = new StringBuilder("");
for (byte value : b) {
i = value;
if (i < 0) {
i += 256;
}
if (i < 16) {
buf.append("0");
}
buf.append(Integer.toHexString(i));
}
return buf.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
}
```
您可以调用该类的md5方法进行字符串的MD5加密,如下所示:
```java
String str = "Hello, world!";
String encryptedStr = MD5Util.md5(str);
System.out.println(encryptedStr); // 输出:6cd3556deb0da54bca060b4c39479839
```
java十六进制转十进制工具类
下面是一个Java的十六进制转十进制的工具类:
```java
public class HexToDecimal {
public static int hexToDecimal(String hex) {
int decimal = 0;
String digits = "0123456789ABCDEF";
hex = hex.toUpperCase();
for (int i = 0; i < hex.length(); i++) {
char c = hex.charAt(i);
int d = digits.indexOf(c);
decimal = 16*decimal + d;
}
return decimal;
}
}
```
使用方法:
```java
String hex = "1A";
int decimal = HexToDecimal.hexToDecimal(hex);
System.out.println(decimal); // Output: 26
```
注意,这个工具类只支持大写的十六进制字符串。如果需要支持小写的十六进制字符串,可以在方法中增加一行代码:
```java
hex = hex.toUpperCase();
```
将所有的小写字符转换为大写字符。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)