Detailed introduction to API in Java
①Strings are all objects
②Once initialized, they cannot be changed because they are constants.
③You can know through the constructor of the String class to convert a byte array or character into a string.
int lastIndexOf(int ch) | |
boolean endsWith(String suffix) | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
5. Commonly used methods of StringBuffer class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
StringBuffer deleteCharAt(int index) | |
StringBuffer replace(int start ,int end, String str) | |
String toString() | |
Example: |
1 2 3 4 5 6 7 |
|
6. The difference between StringBuffer and String
②The String class covers the equals() method of the Object class, but the StringBuffer class does not.
③String class objects can be connected using operator +, but StringBuffer class objects cannot.
2. Common methods of System classstatic long currentTimeMills() | |
static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length) | ##static Properties getProperties()static String getProperty( String key) |
The Runtime class is used to represent the status of the virtual machine when it is running. It is used to encapsulate the JVM virtual machine process. Instance method: Runtime run = Runtime.getRuntime(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
int nextInt() | int nextInt(int n) | ||||||||||||||||||
示例:
Copy after login 运行结果:
Copy after login 四、针对日期类型的操作类有三个,分别是java.util.Date,java.util.Calendar和 java.text.DateFormat 。
1、Date类用于表示日期和时间:其中构造方法:
①Date()用于创建当前日期时间的Date对象,
②Date(long date)用于创建指定时间的Date对象。创建如:
Date date1 = new Date();
Date date2 = new Date(9666546565L );
2、Calendar类用于完成日期和时间字段的操作,为抽象类,不能被实例化,在程序中需要调用其静态方法getInstance()来得到一个Calendar对象,然后调用其相应的方法:
Calendar calendar = Calendar.getInstance();
Calendar常用方法:
注意:Calendar.MONTH字段月份的起始值是从0开始而不是1 。
示例:
Copy after login 运行结果:
Copy after login
3、DateFormat类,专门用于将日期格式化为字符串或者用特定格式显示的日期字符串转换成一个Date对象,抽象类不可实例化,但提供静态方法。
SimpleDateFormat ,DateFormat类子类,可通过new创建实例对象, 是一个以语言环境敏感的方式来格式化和分析日期的类。SimpleDateFormat 允许你选择任何用户 自定义日期时间格式来运行。如:
SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
这一行代码确立了转换的格式,其中 yyyy 是完整的公元年,MM 是月份,dd 是日期,HH:mm:ss 是时、分、秒。
注意:有的格式大写,有的格式小写,例如 MM 是月份,mm 是分;HH 是 24 小时制,而 hh 是 12 小时制。
以上实例编译运行结果如下:
Current Date: Sun 2014.07.18 at 14:14:09 PM PDT
其中parse(String source)方法,它试图按照给定的SimpleDateFormat 对象的格式化存储来解析字符串。
示例:
Copy after login 运行结果:
Copy after login
|
The above is the detailed content of Detailed introduction to API in Java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to the Armstrong Number in Java. Here we discuss an introduction to Armstrong's number in java along with some of the code.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is
