Java API 汇总(未完待续)

-java.lang.Math
static int		Math.abs(int);			the absolute value
static long		Math.abs(long);			the absolute value
static float		Math.abs(float);		the absolute value
static double		Math.abs(double);		the absolute value
static double		Math.cos(double);		the cosine value, the argument is a radian value
static double		Math.sin(double);		the sine value, the argument is a radian value
static double		Math.tan(double);		the tangent value, the argment is a radian value
static double		Math.log(double);		the natural logarithm value
static double		Math.exp(double);		the exponential value
static double		Math.log10(double);		the base 10 logarithm value
static double		Math.pow(double);		the power value
static int		Math.min(int, int);		the minimum value
static long		Math.min(long, long);		the minimum value
static float		Math.min(float, float);		the minimum value
static double		Math.min(double, double);	the minimum value
static int		Math.max(int, int);		the maximum value
static long		Math.max(long, long);		the maximum value
static float		Math.max(float, float);		the maximum value
static double		Math.max(double, double);	the maximum value
static double		Math.random();			a random double value between 0 and 1
static long		Math.round(double);		the round value of a double value
static int		Math.round(float);		the round value of a double value
static double		Math.sqrt(double);		the square value
-------------------------------------------------------------------------------------------
-java.lang.Byte
constructor Byte	Byte(byte);
byte			byteValue();			the byte value
int			intValue();			the int value
long			longValue();			the long value
float			floatValue();			the float value
double			doubleValue();			the double value
static byte		Byte.parseByte(String);		the byte value of the String
byte			valueOf(String);
String			toString();
-------------------------------------------------------------------------------------------
-java.lang.Integer
Integer			Integer(int);
byte			byteValue();			the byte value
int			intValue();			the int value
long			longValue();			the long value
float			floatValue();			the float value
double			doubleValue();			the double value
static int		Integer.parseInt(String);	the int value of the String
int			valueOf(String);
String			toString();
-------------------------------------------------------------------------------------------
-java.lang.Long
constructor Long	Long(long);
byte			byteValue();			the byte value
int			intValue();			the int value
long			longValue();			the long value
float			floatValue();			the float value
double			doubleValue();			the double value
static long		Long.parseLong(String);
long			valueOf(String);
String			toString();
-------------------------------------------------------------------------------------------
-java.lang.Float
constructor Float	Float(float);
byte			byteValue();			the byte value
int			intValue();			the int value
long			longValue();			the long value
float			floatValue();			the float value
double			doubleValue();			the double value
static float		Float.parseFloat(String);
float			valueOf(String);
String			toString();
-------------------------------------------------------------------------------------------
-java.lang.Double
constructor Double	Double(double);
byte			byteValue();			the byte value
int			intValue();			the int value
long			longValue();			the long value
float			floatValue();			the float value
double			doubleValue();			the double value
static double		Double.parseDouble(String);
double			valueOf(String);
String			toString();
-------------------------------------------------------------------------------------------
-java.lang.Short
constructor Short	Short(short);
short			shortValue();
static short		Short.parseShort(String);
short			valueOf(String);
String			toString();
-------------------------------------------------------------------------------------------
-java.lang.Boolean
constructor Boolean	Boolean(boolean);
boolean			booleanValue();
static boolean		Boolean.parseBoolean(String);
boolean			valueOf(String);
String			toString();
-------------------------------------------------------------------------------------------
-java.lang.Character
constructor Character	Character(char);
char			charOf(String);
String			toString();
-------------------------------------------------------------------------------------------
-java.math.BigDecimal
constructor BigDecimal	BigDecimal(int);
constructor BigDecimal	BigDecimal(long);
constructor BigDecimal	BigDecimal(float);
constructor BigDecimal	BigDecimal(double);
constructor BigDecimal	BigDecimal(String);
int			intValue();
long			longValue();
float			floatValue();
double			doubleValue();
String			toString();
BigDecimal		add(BigDecimal);
BigDecimal		subtract(BigDecimal);
BigDecimal		multiply(BigDecimal);
BigDecimal		divide(BigDecimal);
-------------------------------------------------------------------------------------------
-java.text.NumberForamt
static String		NumberFormat.format(int);
static String		NumberFormat.format(long);
static String		NumberFormat.format(float);
static String		NumberFormat.format(double);
static String		NumberFormat.format(long);
static NumberFormat	NumberFormat.getCurrencyInstance();
static NumberFormat	NumberFormat.getCurrencyInstance(java.util.Locale);
static NumberFormat	NumberFormat.getPercentInstance();
static NumberFormat	NumberFormat.getPercentInstance(java.util.Locale);
static NumberFormat	NumberFormat.getNumberInstance();
static NumberFormat	NumberFormat.getNumberInstance(java.util.Locale);
static void		NumberFormat.setMinimumFractionDigits(int);
static void		NumberFormat.setMaximumFractionDigits(int);
-------------------------------------------------------------------------------------------
-java.text.DecimalFormat extends NumberFormat
How to use "000,000"?
How to use "#"?
-------------------------------------------------------------------------------------------
-java.util.Locale
static Locale		CANADA
static Locale		CHINA
static Locale		FRANCE
static Locale		GERMANY
static Locale		ITALY
static Locale		JAPAN
static Locale		KOREA
static Locale		PRC
static Locale		TAIWAN
static Locale		UK
static Locale		US
--------------------------------------------------------------------------------------------java.util.Scannerconstructor Scanner(InputStream)boolean hasNext()String next()static Integer parseInt(String)static Long parseLong(String)static Double parseDouble(String)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Java中,泛型是一种强类型机制,它可以让你在编译时检查类型错误,从而提高代码的安全性和可读性。在使用泛型时,我们经常会遇到父类和子类的泛型转换问题。 首先,我们需要明确一点:子类泛型不能转换成父类泛型。这是因为Java中的泛型是不协变的。例如,如果有一个类A和它的子类B,那么List<A>和List<B>之间是不存在继承关系的。 下面我们来看一个例子: ```java public class Animal { //... } public class Dog extends Animal { //... } public class Test { public static void main(String[] args) { List<Animal> list1 = new ArrayList<>(); List<Dog> list2 = new ArrayList<>(); list1 = list2; // 编译错误 } } ``` 在这个例子中,我们定义了Animal类和它的子类Dog。然后我们定义了两个List,分别是List<Animal>和List<Dog>。如果将List<Dog>赋值给List<Animal>,会出现编译错误。这是因为List<Animal>和List<Dog>之间不存在继承关系。 那么,如果我们想要让子类泛型转换成父类泛型,应该怎么办呢?这时我们可以使用通配符来解决问题。通配符可以表示任意类型,包括父类和子类。例如,我们可以将List<Dog>赋值给List<? extends Animal>,这样就可以实现子类泛型转换成父类泛型了。 下面我们来看一个使用通配符的例子: ```java public class Animal { //... } public class Dog extends Animal { //... } public class Test { public static void main(String[] args) { List<Animal> list1 = new ArrayList<>(); List<Dog> list2 = new ArrayList<>(); list1 = list2; // 编译错误 List<? extends Animal> list3 = new ArrayList<>(); list3 = list2; // 正确 } } ``` 在这个例子中,我们定义了List<? extends Animal>来表示任意继承自Animal的类型。然后我们将List<Dog>赋值给List<? extends Animal>,这样就可以实现子类泛型转换成父类泛型了。 总结一下,Java中的泛型是不协变的,子类泛型不能转换成父类泛型。如果需要实现子类泛型转换成父类泛型,可以使用通配符来解决问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

钟超

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值