. Name.compareto (s.name): num; the //the name is the same length and content, does not mean the same age, so you have to continue to judge the age + intnum3 = Num2 = = 0? This. Age-s.age:num2; - returnnum3; $ } $}(2)Treesetdemo. Java:1 Packagecn.itcast_06;2 3 ImportJava.util.TreeSet;4 5 /*6 * Requirements: Please follow the name of the length of the order7 */8 Public classTreesetdemo {9 Public Static voidMain (string[] args) {Ten //To create a collect
()); //System.out.println (It.next ()); //The last one should not be written, so we should have a judgment before each acquisition//Judging whether there is the next element, there is to get it, not to ignore it//if (It.hasnext ()) {//System.out.println (It.next ()); // } //if (It.hasnext ()) {//System.out.println (It.next ()); // } //if (It.hasnext ()) {//System.out.println (It.next ()); // } //if (It.hasnext ()) {//System.out.println (It.next ()); // } //if (It.has
1. Use of the Aslist () method in the Arrays tool class1 Public static arrays into setsPrecautions:Although you can turn an array into a collection, the length of the collection cannot be changed .2. code example:(1)1 Packagecn.itcast_03;2 3 Importjava.util.Arrays;4 Importjava.util.List;5 6 /*7 * public static 8 * 9 * Precautions:Ten * Although you can turn an array into a collection, the length of the collection cannot be changed. One */ A Public classArraysdemo { - Public Static voi
) { - //System.out.println (objs[x]); - //I know that the element is a string, and I want to know the length of the element while I get the element. - //System.out.println (objs[x] + "---" + objs[x].length ()); - //the above implementation is not possible, becausethere is no length () method in Object in //If we want to use the string method, we must restore the element to a string - //Down Transformation toString s =(Stri
1. Collection collection stores strings and iterates throughAnalysis:(1) Creating a Collection Object(2) Creating a String Object(3) Adding a String object to the collection(4) Traversing the collection2. code example:1 Packagecn.itcast_04;2 3 Importjava.util.ArrayList;4 Importjava.util.Collection;5 ImportJava.util.Iterator;6 7 /*8 * Requirement: Store string and traverse. 9 * Ten * Analysis: One * A: Create A Collection Object A * B: Create a String object - * C: Add a String object to the
1. You can refer to the previously written notes: Android (Java) Learning Note 167:java The class description of the action file (file + IO stream)2. FileOutputStream (Common) method of construction:FileOutputStream(Filefile)Constructs a new fileoutputstream on the File file .FileOutputStream(Stringfilename)Constructs a new fileoutputstream on the file named filename .3. code example:1 PackageCom.himi.fileoutputstream;2 3 ImportJava.io.File;4 Importjava.io.FileNotFoundException;5 ImportJava.io.
1. Recursion:method to invoke the behavior of the method itself in the definition.e.g:1 Public void Show (int n) {2 if(n ) { 3 System.exit (0); 4 }5 System.out.println (n); 6 Show (--n); 7 }Precautions:(1) recursion must have an exit, otherwise it is the cycle of death(2) The number of recursion can not be too many, otherwise memory overflow(3) construction method cannot be used recursivelyJava Fundamentals
. (father is broken, son can not be worse than father)Ten * B: If the parent throws multiple exceptions, the subclass overrides the parent class and can only throw the same exception or a subset of his, the subclass cannot throw exceptions that the parent class does not have. (father is broken, son can not be worse than father) One * C: If the overridden method does not throw an exception, then the method of the child class is absolutely not to throw an exception, if there is an exception in the
1. Store the data in the collection into a text file case:Requirement: To store string data in the ArrayList collection into a text file?(1) Analysis:Through the meaning of the topic, we can know some of the following things,A string is stored in the ArrayList collection.Traverse the ArrayList collection to get the data.It is then stored in a text file.The text file description uses a character stream .(2)Data Source :ArraylistDestination :A.txt--FileWriter--BufferedWriter2. code example:1 Pack
character into a portion of an array. A String readLine () - reads a line of text. - BooleanReady () the determines whether this stream is ready to be read. - voidReset () - Resets the stream to the latest markup. - LongSkipLongN) +Skips a character.(3)BufferedReader Use code example:1 Packagecn.itcast_05;2 3 ImportJava.io.BufferedReader;4 ImportJava.io.FileReader;5 Importjava.io.IOException;6 7 /*8 * BufferedReader9 * Reads text from the character input stream, buffering individual cha
1. Bufferedinputstream reading dataBufferedinputstream construction method, as follows:
Construction Method Summary
BufferedInputStream(InputStreamin)Create one BufferedInputStream and save its arguments, that is, the input stream for in future use.
BufferedInputStream(InputStreamin, intsize)creates a specified buffer size BufferedInputStream and saves its arguments, that is, the input stream for in future use.
2. code example:1 Package
character buffer input stream object -BufferedReader br =NewBufferedReader (NewFileReader ("Bw2.txt")); - - //Public String ReadLine (): reads one row of data at a time - //String line = Br.readline (); in //System.out.println (line); - //Line = Br.readline (); to //System.out.println (line); + - //The final version of the code theString line =NULL; * while(line = Br.readline ())! =NULL) { $ System.out.println (line);Panax Notoginseng
1. Traversal of the Map collectionMap--Couples onIdeas:A: Bring all the husbands together.B: Walk through the collection of husbands, get every husband.C: Ask the husband to find his wife.Transformation:A: Get all the keysB: The collection of traversal keys, get each keyC: According to the key to find the value2. code example:1 Packagecn.itcast_01;2 3 ImportJava.util.HashMap;4 ImportJava.util.Map;5 ImportJava.util.Set;6 7 Public classMapDemo3 {8 Public Static voidMain (string[] args) {9
1. HashMap collection (The key is an Integer, the value is a case of String )2. code example:1 Packagecn.itcast_02;2 3 ImportJava.util.HashMap;4 ImportJava.util.Set;5 6 /*7 * hashmap8 * Key: Integer9 * Value: StringTen */ One Public classHashMapDemo2 { A Public Static voidMain (string[] args) { - //To create a collection object -HashmapNewHashmap(); the - //creating elements and adding elements - //integer i = new integer; - //Integer i =; + //Str
1. Because the byte stream operation Chinese is not particularly convenient , so Java provides the conversion stream .Character stream = byte stream + encoding table2. Coding tableA table consisting of characters and their corresponding valuesCommon Coding tables:Ascii/unicode Character Set• Iso-8859-1• gb2312/gbk/gb18030• BIG5• UTF-83. Encoding and decoding problems in the String class:(1) Using construction method in string: ( decoding )String(byte[]bytes, StringcharsetName)Constructs a new on
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.