美文网首页Java 重学笔记
Java-基本类型 char

Java-基本类型 char

作者: Lucifer_yls | 来源:发表于2017-08-28 22:57 被阅读0次

1:大小16-bit,最小值:Unicode 0,最大值:Unicode 2^16-1,包装器类型Character

2:初始化默认值 '\u0000' (null)

3:一些需要注意的地方

Java为Unicode编码,UTF-8、UTF-16、UTF-32是Unicode的实现形式,而ASCII为Unicode的子集。

在编程应用中应该注意的是不同系统的文件分割符、路径分隔符、行分隔符

File类有几个类似separator的静态字段,都是与系统相关的,在编程时应尽量使用。

File.separatorChar    

public static final charString separator

与系统有关的默认名称分隔符。此字段被初始化为包含系统属性 file.separator 值的第一个字符。在 UNIX 系统上,此字段的值为 ‘/’;在 Microsoft Windows 系统上,它为 ‘\’。

File.separator         

public static final String separatorcharseparatorChar

与系统有关的默认名称分隔符,为了方便,它被表示为一个字符串。此字符串只包含一个字符,即 separatorChar。

File.pathSeparatorChar    

public static final char pathSeparatorChar

与系统有关的路径分隔符。此字段被初始为包含系统属性 path.separator 值的第一个字符。此字符用于分隔以路径列表 形式给定的文件序列中的文件名。在 UNIX 系统上,此字段为 ‘:’;在 Microsoft Windows 系统上,它为 ‘;’。

File.pathSeparator

public static final String pathSeparator

与系统有关的路径分隔符,为了方便,它被表示为一个字符串。此字符串只包含一个字符,即 pathSeparatorChar。

通过获取平台相关信息也可获得以上相关属性

import java.util.Properties;

public class SeparatorUtils {

/* system properties to get separators */

static final Properties PROPERTIES = new Properties(System.getProperties());

/**

* get line separator on current platform

* @return line separator

*/

public static String getLineSeparator(){

return PROPERTIES.getProperty("line.separator");

}

/**

* get path separator on current platform

* @return path separator

*/

public static String getPathSeparator(){

return PROPERTIES.getProperty("path.separator");

}

}

class SeparatorUtilTest{

public static void main (String[] args){

System.out.println("Line separator is: " + SeparatorUtils.getLineSeparator());

System.out.println("Path separator is: " + SeparatorUtils.getPathSeparator());

}

}

【附注】

其他能得到的属性:

相关文章

  • Java-基本类型 char

    1:大小16-bit,最小值:Unicode 0,最大值:Unicode 2^16-1,包装器类型Characte...

  • java 基本类型

    java 基本类型 基本类型 java 基本的基本类型包括 boolean, byte, char, short,...

  • 结构体的基本概念

    基本数据类型: int double float char构造类型: 数组/ 结构体人:姓名: // char *...

  • java lang包下Character类

    Character 类在对象中包装一个基本类型 char 的值。Character 类型的对象包含类型为 char...

  • java中的数据类型

    java数据分为基本类型和引用类型。 一、基本类型 基本类型主要有八种:boolean、char、short、in...

  • 编程学习笔记三(变量、常量及数据类型)

    C变量类型分为 基本类型、枚举类型、void类型、派生类型。基本类型:char(1字节),unsigned cha...

  • 2019-08-18数据类型

    1基本数据类型 数据类型分为2类:基本数据类型、复合类型基本类型:char、short、int、long、floa...

  • java 02

    基本的语法 八种基本类型,整数类型(byte short int long )文本类(char)浮点类型(doub...

  • 2018-10-31 java 拆箱-装箱

    Java 基本数据类型 基本数据类型:byte,short,int,long,char,float,double,...

  • 基本数据类型、常量变量及运算符

    一、基本数据类型 // char—字符类型 // short—短整数类型 // int—整数类型 // lon...

网友评论

    本文标题:Java-基本类型 char

    本文链接:https://www.haomeiwen.com/subject/lelndxtx.html