Java Basic Class Learning notes (one) API Common class (i)

Source: Internet
Author: User

Use of 1:scanner (learn)(1) The class that appears after JDK5 for keyboard input data.   (2) Construction method: A: Explained system.in this thing.      It is actually the standard input stream, corresponding to the keyboard entry B: Construction method InputStream is = system.in; Scanner (InputStream is) C: Common format Scanner sc = new Scanner (system.in); (3) Basic method Format:A:hasnextxxx () determines whether a type of b:nextxxx () returns some type of element Basic FormatHasnextxxx () Determines if there is a next entry, where xxx can be int,double, and so on. If you need to decide whether to include the next string, you can omit xxx nextxxx () to get the next entry. The meaning of xxx and the previous method of the same as XXX by default, scanner use spaces, enter and so on as separators (4) to master the two methods A:public int nextint () b:public String nextline () (5) minor issues to be aware ofA : The same scanner object, get the value first, and then get the string there will be a small problem. B: The solution:A: Redefine a scanner objectB: Get all the data in a string and then convert it accordingly Overview and use of the 2:string class (Master/Important)(1) A string of data consisting of multiple characters. In fact, it can be converted to a character array. (2) Construction method: A:public string () B:public string (byte[] bytes) C:public string (byte[] bytes,int offset,int length) d:public String (char[] value) E:public string (char[] value,int offset,int count) f:public string (string original) this one, although not a construction method , but the result is also a string object g:string s = "Hello"; (3) character of the stringA: Once the string is assigned, it cannot be changed.  Note: This refers to the contents of the string cannot be changed, not the reference cannot be changed. B: The literal value as a string object and the different string s = new string ("Hello") created by constructing the object, and the difference between string s = "Hello"? /* #面试题 #* String s = new string ("Hello") and string s = "Hello"; Have The former creates 2 objects, which create 1 objects. * * ==: Compare reference types Compare if address values are the same * equals:Comparing reference types By default is also the same as comparing address values, and the string class overrides the Equals () method to compare whether the content is the same. */(4) the face question of a string (see program write result) a:== and Equals ()string S1 = new String ("Hello");   String s2 = new string ("Hello");   System.out.println (S1 = = s2);//False System.out.println (S1.equals (S2));//true string s3 = new String ("Hello");   String s4 = "Hello";   System.out.println (s3 = = S4);//False System.out.println (S3.equals (S4));//true String s5 = "Hello";   String s6 = "Hello"; System.out.println (S5 = = s6);//True System.out.println (S5.equals (S6));//True B: Concatenation of strings/* * See Program Write Results * String If the variable is added, first open space, in stitching. * String If the constant is added, is added first, then in the constant pool to find, if there is a direct return, otherwise, created.   */String S1 = "Hello";   String s2 = "World";   String s3 = "HelloWorld"; System.out.println (S3 = = S1 + s2);//False System.out.println (S3.equals ((S1 + s2));//True System.out.println (s3 = = "Hello" + "world");//False This we are wrong, should be true System.out.println (s3.equals ("Hello" + "world");//True (5) function of string (self-completion method Chinese meaning) A: Judging functionBoolean equals (Object obj)//Determines whether the contents of the string are the same, case-sensitive Boolean equalsignorecase (String str)//Boolean contains (string STR) Boolean startsWith (String str) Boolean endsWith (String str) Boolean isEmpty () B: Get featuresint length () char charAt (int index) int indexOf (int ch) int indexOf (String str) int indexOf (int ch,int fromIndex) int indexOf (String str,int fromIndex) string substring (int start) string substring (int start,int end) C: Conversion functionByte[] GetBytes () char[] ToCharArray () static string ValueOf (char[] CHS) static string valueOf (int i) string tolow Ercase () string toUpperCase () string concat (String str) D: Other functions A: Replace functionString replace (char Old,char new) string Replace (string old,string new) B: Go to space functionString Trim () C: Compare functions by Dictionaryint CompareTo (string str) int comparetoignorecase (String str) (6) string case A: Impersonate User logon B: string traversal C: Count uppercase, lowercase, and numeric characters in the statistics string D: the word The first letter of the string is converted to uppercase, and the other lowercase E: The int array is stitched into a string of the specified format F: string inversion G: Count the number of occurrences of a large string of small strings

Java Basic Class Learning notes (one) API Common class (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.