Java思维题
2021-06-16 09:06
标签:builder lis == lower 不能 目标 参数 重复 i+1 比如: "hello" 中的 h, "hello, how r you?" 中的 e 比如: StringUtil 加密后的结果为 FgevatHgvy,Hello 加密的结果为 Uryyb 比如:“你好啊!” 翻转成 "!啊好你" Java思维题 标签:builder lis == lower 不能 目标 参数 重复 i+1 原文地址:https://www.cnblogs.com/oukele/p/9726579.html1、求取字符串中出现的第一个非重复字符。
2、使用26字符母实现加密
3、翻转一个字符串
4、检查一个字符串是否为空(包括 null 的判断)
实现方法(个人想法):
第一题
//第一种实现方式
public String getIsStr(String str){
String[] arr = str.replaceAll("\\s","").split("");
for (int i = 0; i
第二题
public String rotate(String str){
// 接收结果的变量
String result ="";
//"a","b","c","d","e","f","g","h","i","j","k","l","m"
//"n","o","p","q","r","s","t","u","v","w","x","y","z"
//大小写字符数组
String [] lower = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
String [] upper = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
//将 目标字符串 去掉 里面一些符号 并且 分割
String [] arr = str.replaceAll("\\s","").split("");
for (int i = 0; i
第三题
//第一种方式
public String reverse(String str){
//将字符 分割成 字符数组
String [] arr = str.split("");
//获取 字符数组的长度
int size = arr.length;
//拿一个结果变量来接收
String result = "";
//循环
for (int i = 0; i
第四题
public boolean isEmpty(String str){
//字符串对象和字符串变量这两个概念的区别
//字符串变量保存一个字符串对象的引用
//判断字符串是否空涉及两个层次
//1、首先判断字符串变量的引用是否为空,即空对象的概念,用null来判断,可以用== null;(注意不能用equals(null),在参数为null情况下,返回值永远是false)
//2、是在不为空对象的情况下,在判断字符串对象是否为空串,即长度为0.用length()==0
if(!( str == null ||str.length() == 0)){
return true;
}
return false;
}
上一篇:c/c++ 数组的智能指针 使用
下一篇:集合00_Java集合框架