字符串数组

字符串:
1.一维数组的定义:
1)type arrayName[];
   类型(type)可以为任意的java 类型。
2)一维数组初始化
     静态初始化
     int intArray[]={1,2,3};
    
     动态初始化
 简单类型如;
 int intArray[];
 intArray=new int[5];
 复合类型如:
 String stringArray=new String[3];
3)一维数组的引用

 


2.多维数组
  二维数组空间不是连续分配的,所以不要求二维数组每一维的大小相同。
 例;
  int a[][]=new int[2][];
  a[0]=new int[3];
  a[1]=new int[5];
  对二维数组,必须首先为最高维分配引用空间,然后再顺次为低维分配空间。
  其中a.length表示行数,a[i].length表示第i行的元素个数。

 

 

2.5 字符串的处理

1) Stiring 表示字符串:
  其中public int length()此方法返回字符串的个数
  public cahr charAt(int index)止方法返回字符串中index位置上的字符,其
  中index值的范围是0~length-1.

  public int indexOf(int ch) 返回指字字符在此字符中第一次出现处的索引
  public lastIndexOf(int ch)返回最后一次出现的指定字符在此字符串中的索引。

  public int indexOf(String str)
  public int lastIndexOf(String str)
这两个方法返回子串str中第一个字符在字符串中出现的第一个和最后一个位置。

   public int indexOf(int ch,int fromIndex)
   public lastIndexOf(int ch,int fromIndex)
这两个方法指从索引开始搜索,返回在此字符串中第一次和最后一次出现在指定
字符处的索引。

   public int indexOf(int ch,int fromIndex)
   public lastIndexOf(int ch,int fromIndex)
返回子串 str中的第一个字符在字符串位置从索引开始出现的第一个和最后一
个的位置。

  public void getchars(int srcbegin,int end,char buf[],int dstbegin)

 srcbegin 为要提取的第一个字符在源串中的位置, end为要提取的最后一个
字符在源串中的位置,字符数组buf[]存放目的字符串,dstbegin 为提取的字符串在目的串中的起始位置。

2)
  用StringBuffer表示字符串

  StringBuffer( ); /*分配16个字符的缓冲区*/
  StringBuffer( int len ); /*分配len个字符的缓冲区*/
  StringBuffer( String s ); /*除了按照s的大小分配空间外,再分配16个
               字符的缓冲区*/

  StringBuffer类中的capacity()方法用来得到在字符串缓冲区的容量,它与
方法length()所返回的值不有同的。

 

3)String类提供的方法:
 
 public String contat(String str);
 
 public String replace(char oldChar,char newChar);
 
  public String substring(int beginIndex);
 public String substring(int beginIndex,int endIndex)
 
  public String toLowerCase();
  public String toUpperCase();

 

4)equals()
  比较两个字符串与指定的对象,当且仅当该参数不为 null,并且是表示与此对象相同的字符序列的 String 对象时,结果才为 true。
  equalsIgnoreCase()
  将此 String 与另一个 String 进行比较,不考虑大小写。如果两个字符串的长度相等,并且两个字符串中的相应字符都相等(忽略大小写),则认为这两个字符串是相等的。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值