首页 > 编程语言 > 详细

Java String

时间:2020-07-11 21:07:25      阅读:62      评论:0      收藏:0      [点我收藏+]

A Question

技术分享图片
技术分享图片


技术分享图片


IMPORTANT
技术分享图片

This Question

技术分享图片
方法外的变量与其通过参数传递到方法内的变量 虽然名字以及值或者说地址是一样的,但这两者根本不是同一个变量。

Some Methods

技术分享图片
技术分享图片

 @Test
    public void testString(){
       String s1 = "78This904is325Truman9845Speaking";
       s1 = s1.replaceAll("\\d+", "_");
        System.out.println(s1);   // _This_is_Truman_Speaking
    }
  @Test
    public void testMatches(){
        String tel = "0558-2364015";
        boolean matches = tel.matches("0558-\\d{7,8}");
        System.out.println(matches);  // true
    }
@Test
    public void testSplit(){
        String s1 = "I_love_Villanelle";
        String[] split = s1.split("\\_");
        System.out.println(Arrays.toString(split));
    }

String -> byte[]

  @Test
    public void testByte(){
        String str1 = "Villanelle";
        byte[] bytes = str1.getBytes();
        System.out.println(Arrays.toString(bytes)); // [86, 105, 108, 108, 97, 110, 101, 108, 108, 101]
    }

Variable String -> StringBuffer & StringBuilder

Little Trick: there is letter f in StringBuffer, so, StringBuffer is Thread Safe


StringBuffer和 StringBuilder 默认的char[] 大小为16, 也可以指定, 扩容为 capacity * 2 + 2

Methods in StringBuffer

技术分享图片

Java String

原文:https://www.cnblogs.com/nedrain/p/13285209.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!