7-18 常用类下
来源:互联网 发布:android照相机源码 编辑:程序博客网 时间:2024/06/08 16:36
循序渐进
一 StringBuffer
1)StringBuffer代表可变的字符序列
即运算后,此内存区域内容发生改变
2)String代表不可变字符,运算即复制原有值在新出现的内存区域留下结果
3)
public class StringBuff { public static void main(String[] args) { String t = "Mis"; char[] a = {'a','b','c'}; StringBuffer s = new StringBuffer(t); s.append('/').append("IBM").append('/').append("Sun");//append不断添加字符串 System.out.println(s); StringBuffer s1 = new StringBuffer("数字"); for(int i=0; i<=9; i++) { s1.append(i);//添加数字 } System.out.println(s1); s1.delete(8,s1.length()).insert(0,a);//令s1从第八位截断。留下 数字012345 添加a在第0位 System.out.println(s1); System.out.println(s1.reverse());//倒序s1 }}
二
public class Doubl { public static void main(String[] args) { double[][] d; String s = "1,2;3,4,5;6,7,8"; String[] sp = s.split(";"); d = new double[sp.length][]; for(int i=0; i<sp.length; i++){ //System.out.println(sp[i]);//验证是否分对 String[] sp1 = sp[i].split(","); d[i] = new double[sp1.length]; for(int j=0; j<sp1.length; j++) { d[i][j] = Double.parseDouble(sp1[j]); System.out.println(sp1[j]); }//多打印东西有利于调试程序 } for(int i=0; i<d.length; i++){ for(int j=0; j<d[i].length; j++) { System.out.print(d[i][j]+" "); } } System.out.println(); }}
三
编写一个程序,在命令行中以树状结构展现特定的文件夹及其子文件(夹)
private static void tree(File f, int level) {//递归 String preStr = ""; for(int i=0; i<level; i++){ preStr +=" ";//空格 } File[] childs = f.listFiles(); for(int i=0; i<childs.length; i++) { System.out.println(preStr + childs[i].getName()); if(childs[i].isDirectory()) { tree(childs[i], level +1); } } } }
四 枚举类型
基本用法
public class TestEnum { public enum MyColor {red, green, blue};//定义新类型 此类型变量只能取红绿蓝 public static void main(String[] args) { MyColor m = MyColor.red; switch(m) { case red: System.out.println("red"); break; case green: System.out.println("green"); break; default: System.out.println(m); } } }
五 包装类
public class BaoZhuang { public static void main(String[] args) { Integer i = new Integer(100);//栈空间的i指向堆空间的100 Double d = new Double("123.456"); int j = i.intValue()+d.intValue();//去掉小数点后数字 float f = i.floatValue()+d.floatValue(); System.out.println(j); System.out.println(f); double pi = Double.parseDouble("3.1415926");//转换为double型数 double r = Double.valueOf("2.0").doubleValue();//转换为double类型对象 求Double类型数 double s = pi*r*r; System.out.println(s); try{ int k = Integer.parseInt("1.25");//字符串无法转为int型 } catch (NumberFormatException e) { System.out.println("数据格式不对!"); } System.out.println(Integer.toBinaryString(123)+"B");//以二进制形式表示 System.out.println(Integer.toHexString(123)+"H");//以八进制 System.out.println(Integer.toOctalString(123)+"O");//十六进制 }}
阅读全文
0 0
- 7-18 常用类下
- JAVA(五)常用类下
- 【android,18】android下常用组件:
- Windows 7下的常用shell命令
- java面向对象下:常用类
- 13_IO(其他常用类)(下)
- Microsoft.VisualBasic下的常用类
- Foundation框架下的常用类
- eclipse下查看常用Java类源码
- linux下常用网络工具
- c#下常用函数
- Delphi下常用转换
- Ubuntu下常用操作
- Eclipse下常用快捷键
- 常用操作。备下
- 常用windows下命令
- Linux下常用缩写
- Linux下常用文件系统
- 一个错误
- java并发编程实战-避免活跃性危险
- 3532:最大上升子序列和
- JAVA 文档注释
- 异常处理
- 7-18 常用类下
- linux 下 mysql命令行
- 所有的惠普机器!区别对待
- springmvc报的service空指针的异常
- 几个简单的system(const char* _Command)函数命令
- Unity3D学习记录——API IEnumerator(协同程序)
- 第三章 Java符号相关
- Java 多线程规范(2)线程池详解
- 关于Spring事务管理中@Transactional的参数配置