学习java记录

来源:互联网 发布:人工智能论文话题英文 编辑:程序博客网 时间:2024/06/11 21:54

自己学习java,发现许多新的用处,记录下来。多多复习。

String的用法:根据cracking the coding 习题总结

String str=new String();
str.charAt(i): return the char value at certain index
Arrays.sort(); return the ascend permutation of Char[], byte,double,float, int)
s.toCharArray(); 变成chararray,才能够做很多每一位每一位的操作 1.3,1.4,但是也不见得会有很多很多有用的地方
chararry to string : String s=new String(chararray);
s.indexOf('str')   return -1 没有,返回出现‘str'的第一位

s.replace("s","new");
s.trim();去空格


StringBuffer的使用:会高效,但是需要两步 StringBuffer s=new StringBuffer(); for s.append(xx) s.toString()才能够弄好

Input 读入: 
Scanner s.nextLine() 才能够读取一行有space的string


MD: Char array 直接打出来就可以了。
MD: 直接把int 转换成char 需要考虑其aska码的转换,所以最好不要这么做,最好用string来粘上。
MD: int 不见得是1位,所以说要用String.valueof(int)转换成多位的字符串进行输出才比较合适。





File 相关技巧:
File f = new File("test.text"); 建立新文件
File dir= new File("sdfsdf\");
File file[] allfiles=dir.listFiles(); 返回一个file的数组
File.getabsolutepath();// 返回文件的绝对路径



class: objects that have the same features
Method:don't change the value of the object,
             access the object  unchanged

             mutator change the object


             Shared objects by two variables: 用两个变量同时指向一个object 
int 是一种type ,object的reference才像copy指针;
constructor: 
    public class AA{


                    public AA
                    } 

0 0
原创粉丝点击