JAVA 攻城狮 第十三天

今天算是正式的暑假的第一天
然后今天早上起床很晚 然后起床之后还没有吃早饭 把宿舍小小的整理一下
然后去了实验室 开始看java 没有看视频 看的是Java的书
看类和方法这块觉得看的不是很懂就先跳过了然后看的String类
下面会总结一下String类的构造方法

package StringDemo;
//String类的构造方法详解
//方法一:**String();**
//方法二:**String(byte[] bytes)**
//方法三:**String (byte[] bytes,int index,int length)**
//方法四:**String(char[] value)**
//方法五:**String(char[] value,int index,int length)**
//方法六:**String(String str)**
public class StringDemo1 {

    public static void main(String[] args) {
        //方法一:String();
        String s1=new String();
        //String这个类重写了Object父类的方法,return this;
        System.out.println("s1:"+s1);
        System.out.println("s1.length:"+s1.length());
        System.out.println("---------------------");

        //方法二:String(byte[] bytes)
        byte[] byts={97,98,99,100,101,102};
        String s2=new String(byts);
        System.out.println("s2:"+s2);
        System.out.println("s2.length:"+s2.length());
        System.out.println("---------------------");

        //方法三:String (byte[] bytes,int index,int length)
        byte[] byts2={97,98,99,100,101,102};
        String s3=new String(byts2,2,4);
        System.out.println("s3:"+s3);
        System.out.println("s3.length:"+s3.length());
        System.out.println("---------------------");

        //方法四:String(char[] value)
        char [] value={'a','b','c','d','e','f'};
        String s4=new String(value);
        System.out.println("s4:"+s4);
        System.out.println("s4.length:"+s4.length());
        System.out.println("---------------------");

        //方法五:String(char[] value,int index,int length)
        char [] value2={'a','b','c','d','e','f'};
        String s5=new String(value,2,4);
        System.out.println("s5:"+s5);
        System.out.println("s5.length:"+s5.length());
        System.out.println("---------------------");

        //方法六:String(String str)
        String s6=new String("abcdef");
        System.out.println("s6:"+s6);
        System.out.println("s6.length:"+s6.length());
        System.out.println("---------------------");

    }

}

然后学习了关于String类的一些方法

1.length()
  Return the length of the string.
  The length is equal to the number of 16-bit Unicode characters in the string.

  public class demo{
     public static void main(String[] args) {
        String str1 = "Are you a student?";
        int n1 = str1.length();
    }
  }

2.substring method
  原型:public String substring(int beginindex,int endindex);
        public String substring(int beginindex);

  public class demo2{
    public static void main(String[] args) {
        String str = "Are you a student?";
        String str1 = str.substring(4,8);
        String str2 = str.substring(8);
    }
  }


3.equals method
   原型:public boolean equals(Object anObject)

   public class demo3{
    public static void main(String[] args) {
        String str1 = "Are you a student?";
        String str2 = "Are you A student?";
        int n1 = str1.equals(str2);  //false
    }
   }

4.indexOf method
   原型:public int indexOf(int ch);//from the beginning;
         public itn indexOf(int ch,int fromindenx);//from the fromindex;

   public class demo4{
    public static void main(String[] args) {
        String str1 = "Are you a student?";
        int n1 = indexOf('e');
        int n2 = indexOf('e',5);
    }
   }

5.compareTo method
   原型:public int compareTo(String anotherstring)

   public class demo5{
    public static void main(String[] args) {
        String str1 = "Are you a student?";
        String str2 = "Are you A student?";
        int n1 = str1.compareTo(str2);

    }
   }

6.replace method
   原型:public String replace (char oldchar,char newchar);

   public class demo6{
    public static void main(String[] args) {
        String str1 = "Are you a student?";
        String str2 = str1.replace('s','t');
    }
   }

7.trim() method
   String str1.trim();
   用于删除字符串开头和结尾的空格.

8.startsWith & endsWith 

   原型:public boolean startsWith(String prefix,int toffset);
         public boolean endsWith(String suffix);

   用处:String str1 = "Are you a student?";
         int n1 = str1.startsWith("you",4);
         从第四个开始检测子字符串是否和参数相同 返回布尔值
         int n2 = str1.endsWith("dent"); 
         从最后开始检查子字符串是否和参数相同 返回布尔值

这些是下午看java整理的知识点 晚上要开会 然后晚上可能会去看算法和数据结构
然后今天的总结差不多就这么多吧
好了 老规矩

假期是你超越对手最好的时间
你可以停止学习,但是你的竞争对手可不会
所以,好好利用吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值