学习使用jdk官方api文档

首先是api文档的地址,通常用浏览器打开这个网址进行api查询
https://docs.oracle.com/javase/8/docs/api/
下面简述一些常用类的常用方法

  • System System是在lang包里的一个类,该类提供了标准的输入输出,以及error的输出,用于声明正确的环境变量,还可以复制列表的部分。
    该类的Field有三个:
    Fields Modifier and Type Field and Description
    static PrintStream err
    The “standard” error output stream.
    static InputStream in
    The “standard” input stream.
    static PrintStream out
    The “standard” output stream.

常用的method有以下
Modifier and Type Method and Description

static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array.

static String clearProperty(String key)
Removes the system property indicated by the specified key.

static Console console()
Returns the unique Console object associated with the current Java virtual machine, if any.

static long currentTimeMillis()
Returns the current time in milliseconds.

static void exit(int status)
Terminates the currently running Java Virtual Machine.

static void gc()
Runs the garbage collector.

static Map<String,String> getenv()
Returns an unmodifiable string map view of the current system environment.

static String getenv(String name)
Gets the value of the specified environment variable.

static Properties getProperties()
Determines the current system properties.

static String getProperty(String key)
Gets the system property indicated by the specified key.

static String getProperty(String key, String def)
Gets the system property indicated by the specified key.

static SecurityManager getSecurityManager()
Gets the system security interface.

static int identityHashCode(Object x)
Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object’s class overrides hashCode().

static Channel inheritedChannel()
Returns the channel inherited from the entity that created this Java virtual machine.

static String lineSeparator()
Returns the system-dependent line separator string.

static void load(String filename)
Loads the native library specified by the filename argument.

static void loadLibrary(String libname)
Loads the native library specified by the libname argument.

static String mapLibraryName(String libname)
Maps a library name into a platform-specific string representing a native library.

static long nanoTime()
Returns the current value of the running Java Virtual Machine’s high-resolution time source, in nanoseconds.

static void runFinalization()
Runs the finalization methods of any objects pending finalization.

static void runFinalizersOnExit(boolean value)
Deprecated.
This method is inherently unsafe. It may result in finalizers being called on live objects while other threads are concurrently manipulating those objects, resulting in erratic behavior or deadlock.

static void setErr(PrintStream err)
Reassigns the “standard” error output stream.

static void setIn(InputStream in)
Reassigns the “standard” input stream.

static void setOut(PrintStream out)
Reassigns the “standard” output stream.

static void setProperties(Properties props)
Sets the system properties to the Properties argument.

static String setProperty(String key, String value)
Sets the system property indicated by the specified key.

static void setSecurityManager(SecurityManager s)
Sets the System security.

  • Integer类
    Integer常用于处理整型数的问题,包括对整型数的类包装。
    该类有以下field:
    static int BYTES
    The number of bytes used to represent a int value in two’s complement binary form.

static int MAX_VALUE
A constant holding the maximum value an int can have, 231-1.

static int MIN_VALUE
A constant holding the minimum value an int can have, -231.

static int SIZE
The number of bits used to represent an int value in two’s complement binary form.

static Class TYPE
The Class instance representing the primitive type int.

有以下method:
static int bitCount(int i)
Returns the number of one-bits in the two’s complement binary representation of the specified int value.

byte byteValue()
Returns the value of this Integer as a byte after a narrowing primitive conversion.

static int compare(int x, int y)
Compares two int values numerically.

int compareTo(Integer anotherInteger)
Compares two Integer objects numerically.

static int compareUnsigned(int x, int y)
Compares two int values numerically treating the values as unsigned.

static Integer decode(String nm)
Decodes a String into an Integer.

static int divideUnsigned(int dividend, int divisor)
Returns the unsigned quotient of dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.

double doubleValue()
Returns the value of this Integer as a double after a widening primitive conversion.

boolean equals(Object obj)
Compares this object to the specified object.

float floatValue()
Returns the value of this Integer as a float after a widening primitive conversion.

static Integer getInteger(String nm)
Determines the integer value of the system property with the specified name.

static Integer getInteger(String nm, int val)
Determines the integer value of the system property with the specified name.

static Integer getInteger(String nm, Integer val)
Returns the integer value of the system property with the specified name.

int hashCode()
Returns a hash code for this Integer.

static int hashCode(int value)
Returns a hash code for a int value; compatible with Integer.hashCode().

static int highestOneBit(int i)
Returns an int value with at most a single one-bit, in the position of the highest-
order (“leftmost”) one-bit in the specified int value.

int intValue()
Returns the value of this Integer as an int.

long longValue()
Returns the value of this Integer as a long after a widening primitive conversion.

static int lowestOneBit(int i)
Returns an int value with at most a single one-bit, in the position of the lowest-order (“rightmost”) one-bit in the specified int value.

static int max(int a, int b)
Returns the greater of two int values as if by calling Math.max.

static int min(int a, int b)
Returns the smaller of two int values as if by calling Math.min.

static int numberOfLeadingZeros(int i)
Returns the number of zero bits preceding the highest-order (“leftmost”) one-bit in the two’s complement binary representation of the specified int value.

static int numberOfTrailingZeros(int i)
Returns the number of zero bits following the lowest-order (“rightmost”) one-bit in the two’s complement binary representation of the specified int value.

static int parseInt(String s)
Parses the string argument as a signed decimal integer.

static int parseInt(String s, int radix)
Parses the string argument as a signed integer in the radix specified by the second argument.

static int parseUnsignedInt(String s)
Parses the string argument as an unsigned decimal integer.

static int parseUnsignedInt(String s, int radix)
Parses the string argument as an unsigned integer in the radix specified by the second argument.

static int remainderUnsigned(int dividend, int divisor)
Returns the unsigned remainder from dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.

static int reverse(int i)
Returns the value obtained by reversing the order of the bits in the two’s complement binary representation of the specified int value.

static int reverseBytes(int i)
Returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified int value.

static int rotateLeft(int i, int distance)
Returns the value obtained by rotating the two’s complement binary representation of the specified int value left by the specified number of bits.

static int rotateRight(int i, int distance)
Returns the value obtained by rotating the two’s complement binary representation of the specified int value right by the specified number of bits.

short shortValue()
Returns the value of this Integer as a short after a narrowing primitive conversion.

static int signum(int i)
Returns the signum function of the specified int value.

static int sum(int a, int b)
Adds two integers together as per the + operator.

static String toBinaryString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 2.

static String toHexString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 16.

static String toOctalString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 8.

String toString()
Returns a String object representing this Integer’s value.

static String toString(int i)
Returns a String object representing the specified integer.

static String toString(int i, int radix)
Returns a string representation of the first argument in the radix specified by the second argument.

static long toUnsignedLong(int x)
Converts the argument to a long by an unsigned conversion.

static String toUnsignedString(int i)
Returns a string representation of the argument as an unsigned decimal value.

static String toUnsignedString(int i, int radix)
Returns a string representation of the first argument as an unsigned integer value in the radix specified by the second argument.

static Integer valueOf(int i)
Returns an Integer instance representing the specified int value.

static Integer valueOf(String s)
Returns an Integer object holding the value of the specified String.

static Integer valueOf(String s, int radix)
Returns an Integer object holding the value extracted from the specified String when parsed with the radix given by the second argument.

发布了27 篇原创文章 · 获赞 2 · 访问量 751

猜你喜欢

转载自blog.csdn.net/qq_44028171/article/details/100591683
今日推荐