黑马程序员Java培训、Android培训-Java 学习过程记录_JavaAPI-1

2.1Jcreator开发工具介绍

工作区(jcw)与工程(jcp

使用类向导创建新类;

使用动态随笔功能自动输入功能

指定Jcreator所使用的JDK

设置第三方提供的Jar

指定启动运行类及参数

设置多个运行配置环境

3、  String类和StringBuffer类,位于java.lang包中

3.1 String类对象中的内容一旦被初始化就不能再改变。

3.2 StringBuffer类利用封装内容可以改变的字符串。

       toString方法转换成String类型

       String=“a”+4+“c”;编译时等效于:

       String=new StringBuffer().append(“a”).append(4).append(“c”).toString();

字符串常量(如“hello”)实际上是一种特殊的匿名String对象。比较下面两种情况的差异:

String s1 = hello”;String s2 = hello”;

String s1 = new String(“hello”);String s2 = new String(“hello”);

编程实例:逐行读取键盘输入,直到输入内容为“bye”时,结束程序。

代码:

public class Readline {  

       public static void main(String[] args) {

              // TODO: 在这添加你的代码

              byte [] buf = new byte[1024];

              String strInfo = null;

              int pos = 0;

              int ch = 0;

              while(true)

              {

                     try

                     {

                            ch = System.in.read();

                     }

                     catch(Exception e)

                     {

                            e.printStackTrace();

                     }

                     switch(ch)

                     {

                            case '/r':

                                   break;

                            case '/n':

                                   strInfo = new String(buf,0,pos);

                                   if(strInfo.equals("bye"))

                                   {

                                          return;

                                   }

                                   else

                                   {

                                          System.out.println(strInfo);//

                                          pos = 0;

                                          break;

                                   }

                            default:                               

                                   buf[pos++] = (byte)ch;

                     }

 

              }

       }    

}

3.3String类的常用成员方法:

构造方法:

Stringbyte[] bytes,int offset,int length)将字节数组bytes的第offset位元素起, 取出length个转换为字符串

equalslgnoreCase方法:不区分大小写的情况;

indexOf(int ch)方法:用于返回一个字符:System.out.println(“hello world”.indexOf(‘o’,5));

substring(int beginIndex)方法System.out.println(“hello world”.substringf(6));从第6个元素开始全部输出

<FONT face=""">substring(int beginIndex,int endIndex)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值