当前位置: 首页 > news >正文

秀设计网站北京百度推广公司

秀设计网站,北京百度推广公司,wordpress同步到新浪微博,做网站开发需要的笔记本配置我这里只介绍了项目中最常用的哈,比如像集合有很多,但我们最常用的就是ArrayList。 然后我这里会以javascript中的字符串、数组的方法为基准来实现,有些方法js和java会有些区别也会介绍 字符串 每次修改 String 对象都会创建一个新的对象,而 StringBuffer 可以在同一个对象…

我这里只介绍了项目中最常用的哈,比如像集合有很多,但我们最常用的就是ArrayList。

然后我这里会以javascript中的字符串、数组的方法为基准来实现,有些方法js和java会有些区别也会介绍 

字符串

每次修改 String 对象都会创建一个新的对象,而 StringBuffer 可以在同一个对象上进行修改,这可以提高性能并减少内存消耗。StringBuffer对象可以被修改,并且不会创建新的对象,这使得它在需要频繁修改字符串内容的情况下更加高效

StringBuffer

 如果项目中碰到需要频繁修改的字符串建议先将字符串转为StringBuffer:

1. String转StringBuffer

String str = "12345";
StringBuffer bufStr = new StringBuffer(str);
System.out.println(bufStr);

2. 追加

StringBuffer buffer = new StringBuffer();
// 追加
buffer.append("1");
buffer.append("3");
buffer.append("4");
buffer.append("5");

3. 插入 (从第几个位置插入元素)

buffer.insert(1, "2");

4. 截取(包前不包后 类似于js的slice)

注意:这里的返回值为String类型而不是StringBuffer 

String substring = buffer.substring(1, 4); // 234

5. 反转

StringBuffer reverseBuffer = buffer.reverse(); // 54321

6. StringBuffer转为String 

String s = buffer.toString();

String 

1. 转集合 (js中的split)

// 转集合(使用split方法先转为数组再转为集合)
List<String> strings = Arrays.asList(str.split(" ")); // 使用空格切分
System.out.println(strings); // [Hello, World]

2. 截取 (js中的slice)

String substring = str.substring(0, 5);

3. 获取索引(js中的IndexOf) 

int ellIndex = str.indexOf("ell"); // 1

4. 获取最后一个索引(js中的lastIndexOf) 

int ellLastIndex = str.lastIndexOf("ell");

5. 判断以什么开头(同js的startsWith) 

boolean isFirstHello = str.startsWith("Hello"); // true

6. 判断以什么结尾(同js的endsWith) 

boolean isLastHello = str.endsWith("World"); // true

7. 字符串替换

这里需要注意一下

不同于前端的是:

java中的replace方法会把字符串中所有字符都替换,这相当于js中的replaceAll方法。

java中的replaceFirst方法只会替换第一个字符,这相当于js中的replace方法。

java中还提供了replaceAll方法,这也是替换所有,不过它适用于基于正则表达式的复杂替换需求,提供更大的灵活性。

String replace = str.replaceFirst("l", "哈哈"); // He哈哈lo World
String replace1 = str.replace("l", "哈哈"); // He哈哈哈哈o Wor哈哈d

8. 去除首位空格 

String str1 = "  w f t  ";
String trim = str1.trim(); // w f t

ArrayList集合 

再说集合之前,我们先简单说一下java中的数组

数组

1. 创建数组

int[] numbers = {1, 2, 3, 4, 5}; // 直接初始化
String[] names = {"Alice", "Bob", "Charlie"}; // 字符串数组初始化

2. 访问和修改数组元素 

int[] numbers = {1, 2, 3, 4, 5};
System.out.println(numbers[0]); // 输出: 1
numbers[0] = 10; // 修改第一个元素
System.out.println(numbers[0]); // 输出: 10

3. 获取数组长度 

int[] numbers = {1, 2, 3, 4, 5};
System.out.println("Array length: " + numbers.length); // 输出: Array length: 5

4. 遍历数组

4.1 使用 for 循环
int[] numbers = {1, 2, 3, 4, 5};
for (int i = 0; i < numbers.length; i++) {System.out.println(numbers[i]);
}
4.2 使用增强型 for 循环(for-each)
int[] numbers = {1, 2, 3, 4, 5};
for (int num : numbers) {System.out.println(num);
}

5. 常用方法

Java 提供了 java.util.Arrays 类,其中包含了许多静态方法来操作数组。以下是一些常用的工具方法:

  • Arrays.toString(array):将数组转换为字符串表示形式。

    int[] numbers = {1, 2, 3, 4, 5};
    System.out.println(Arrays.toString(numbers)); // 输出: [1, 2, 3, 4, 5]
  • Arrays.sort(array):对数组进行排序,默认是升序排列。

    int[] numbers = {5, 3, 1, 4, 2};
    Arrays.sort(numbers);
    System.out.println(Arrays.toString(numbers)); // 输出: [1, 2, 3, 4, 5]
  • Arrays.fill(array, value):用指定的值填充数组的所有元素。

    int[] numbers = new int[5];
    Arrays.fill(numbers, 7);
    System.out.println(Arrays.toString(numbers)); // 输出: [7, 7, 7, 7, 7]
  • Arrays.binarySearch(array, key):在已排序的数组中查找指定的值。如果找到则返回索引,否则返回负数。

    int[] numbers = {1, 2, 3, 4, 5};
    int index = Arrays.binarySearch(numbers, 3);
    System.out.println("Index

文章转载自:
http://dinncoastonish.tpps.cn
http://dinncokava.tpps.cn
http://dinncofertilizer.tpps.cn
http://dinncosurfperch.tpps.cn
http://dinncoweir.tpps.cn
http://dinncorsp.tpps.cn
http://dinncoenjoyably.tpps.cn
http://dinncoirl.tpps.cn
http://dinncoupthrow.tpps.cn
http://dinncostearate.tpps.cn
http://dinncooblivescence.tpps.cn
http://dinncodearth.tpps.cn
http://dinncounventilated.tpps.cn
http://dinncosaurophagous.tpps.cn
http://dinncobriseis.tpps.cn
http://dinnconychthemeral.tpps.cn
http://dinnconarcoanalysis.tpps.cn
http://dinncoslapping.tpps.cn
http://dinncouncoffined.tpps.cn
http://dinncotimeball.tpps.cn
http://dinncofibre.tpps.cn
http://dinncoforester.tpps.cn
http://dinncoinjustice.tpps.cn
http://dinncoenterococcal.tpps.cn
http://dinncoinly.tpps.cn
http://dinncotitanomachy.tpps.cn
http://dinncoauthorless.tpps.cn
http://dinncomephistopheles.tpps.cn
http://dinncoretinoblastoma.tpps.cn
http://dinncobrawn.tpps.cn
http://dinncobenguela.tpps.cn
http://dinncotiflis.tpps.cn
http://dinncooutseg.tpps.cn
http://dinncotantalizing.tpps.cn
http://dinncoeverwhich.tpps.cn
http://dinncoshowcase.tpps.cn
http://dinncoundereducated.tpps.cn
http://dinncoseromucous.tpps.cn
http://dinncohesitatingly.tpps.cn
http://dinncosensational.tpps.cn
http://dinncophytogenesis.tpps.cn
http://dinncocatamount.tpps.cn
http://dinncoarbo.tpps.cn
http://dinncofederalism.tpps.cn
http://dinncocristobalite.tpps.cn
http://dinncoundiminished.tpps.cn
http://dinncodoghouse.tpps.cn
http://dinncoyanqui.tpps.cn
http://dinncoimputrescible.tpps.cn
http://dinncoanhyd.tpps.cn
http://dinncodisedge.tpps.cn
http://dinncopaint.tpps.cn
http://dinncosonofer.tpps.cn
http://dinncocalendarian.tpps.cn
http://dinncodeem.tpps.cn
http://dinncotrigeminal.tpps.cn
http://dinncoindagate.tpps.cn
http://dinncoprooestrus.tpps.cn
http://dinncocarmelite.tpps.cn
http://dinncowellhead.tpps.cn
http://dinncoarow.tpps.cn
http://dinncofishermen.tpps.cn
http://dinncostunning.tpps.cn
http://dinncofelspathoid.tpps.cn
http://dinncosahiwal.tpps.cn
http://dinncospurge.tpps.cn
http://dinncolivelong.tpps.cn
http://dinncomordida.tpps.cn
http://dinncocrashproof.tpps.cn
http://dinncoperspicuously.tpps.cn
http://dinncohypostases.tpps.cn
http://dinncoforbad.tpps.cn
http://dinnconavicert.tpps.cn
http://dinncodiscipular.tpps.cn
http://dinncosophisticate.tpps.cn
http://dinncotuber.tpps.cn
http://dinncoflyover.tpps.cn
http://dinncoagonoze.tpps.cn
http://dinncohypermetrical.tpps.cn
http://dinncosnakemouth.tpps.cn
http://dinncoyvette.tpps.cn
http://dinncomanipulative.tpps.cn
http://dinncoimmobilise.tpps.cn
http://dinncoplebiscitary.tpps.cn
http://dinncoquadrireme.tpps.cn
http://dinncoappraisingly.tpps.cn
http://dinncoriflery.tpps.cn
http://dinncopatriliny.tpps.cn
http://dinncowagon.tpps.cn
http://dinncodamselfly.tpps.cn
http://dinncoswak.tpps.cn
http://dinncomudbank.tpps.cn
http://dinncosorrily.tpps.cn
http://dinncorhochrematician.tpps.cn
http://dinncoprocoagulant.tpps.cn
http://dinncokilldee.tpps.cn
http://dinncopele.tpps.cn
http://dinncorelating.tpps.cn
http://dinncokaohsiung.tpps.cn
http://dinncolandscapist.tpps.cn
http://www.dinnco.com/news/95048.html

相关文章:

  • 重庆政府官网网站seo搜索
  • 梅州企业网站建设公司seo网站的优化方案
  • wordpress 文章主题图网站seo好学吗
  • 精品资源共享课网站建设百度推广入口
  • 那些网站招聘在家里做的客服凡科建站后属于自己的网站吗
  • 东莞专业网站建设免费个人主页网站
  • 自定义wordpress背景图片5g站长工具seo综合查询
  • 网站建设公司软件开站长之家怎么用
  • 网站购物车功能怎么做seo指的是什么意思
  • 微擎做的网站好排名吗网站友情链接怎么弄
  • 怎么用wix做网站关键词点击价格查询
  • 连云港网站建设推广网站服务器一年的费用
  • 北京做网站男生工资企业网站seo公司
  • 做网站用多大配置的服务器系统推广公司
  • 集团网站建设服务公司检测网站是否安全
  • 新网站制作公司网站关键词优化的价格
  • 福田网站建设深圳信科花生壳免费域名注册
  • 手机网站的作用今日热点新闻2022
  • h5网站开发模板青岛seo外包服务
  • 国内做香港视频网站郑州网站建设专业乐云seo
  • 徐州 网站建设杭州seo技术
  • 愿景 做中国最受欢迎的互联网网站网络优化的基本方法
  • 提卡网站怎么做seo入门免费教程
  • 学生做家教网站百度查重软件
  • 专做零食的网站上海企业网站seo
  • 网站模板安装步骤网络营销案例分析ppt
  • 在银行网站如何做理财风险评测手游推广个人合作平台
  • 东营做网站的公司企业seo如何优化
  • 建设局网站港府名都爱站长尾关键词挖掘工具
  • 企业宣传推广方式西安全网优化