1. Compare the differences between collection and collections ===== (1), java.util.collection is a collection interface. It provides a common interface method for basic manipulation of collection objects. The collection interface has many specific implementations in the java class library. The meaning of the collection interface is to provide a maximum unified operation for a variety of specific collections . (2) 2, java.util.collections is a wrapper class. It contains a variety of static polymorphic methods related to set operations. This class cannot be instantiated, just like a tool class that serves the Java collection framework. package com.pf; import java.util.arraylist;import java.util.Collections;import java.util.List;import java.util.Random;public class Collectionsdemo { public static void main (String[] args) { List<Integer> list=new ArrayList<Integer> ( //); Generates a random integer within 20 and places it in the list collection list.add (New random (). Nextint (); list.add (New random (). Nextint ()) list.add (New random (). NextInt (20)); list.add (New random () nextint); for (Integer inta:List) { system.out.println (INTA); } system.out.println ("After sorting:"); // Call the Collections tool class to manipulate the list object collections.reverse (list);//Invert Collections.sort (list);//Ascending for (integer inta:list) { system.out.println (INTA); } SYSTEM.OUT.PRINTLN ("Maximum number:" +collections.max (list));
2 ====.==getbytes method ===== function: Gets the byte array of the string
This method uses the default character set of the platform to encode this string into a byte sequence and store the result in a new byte array.
Syntax 1 getBytes ()
The method returns the resulting byte array.
The example uses the GetBytes () function to encode the string strcom into a byte sequence, assign the return value to the STR array, and output the return value.
String strcom = "Java"; Define a string
byte[] str = strcom.getbytes (); Encodes the specified string into a byte sequence
for (int i=0;i<str.length;i++) {//Output return array
System.out.println (Str[i]);
}
Syntax 2 getBytes (Charset Charset)
CharSet: The charset used to encode a string.
The example uses the GetBytes () function to encode the string strcom with the default character set of the Java Virtual machine as a byte sequence, assigns the return value to the STR array, and outputs the return value.
String strcom = "Java"; Define a string
byte[] str = strcom.getbytes (Charset.defaultcharset ());
Encodes the specified string with the default encoding of the Java Virtual machine as a byte sequence
for (int i=0;i<str.length;i++) {//Output return array
System.out.println (Str[i]);
}
Syntax 3 getBytes (String charsetname)
The Charsetname:charsetname is a supported charset.
The example uses the GetBytes () function to encode the string strcom with GBK as a byte sequence, assigns the return value to the STR array, and outputs the return value.
String strcom = "Java"; Define a string
Byte[] STR;
try {
Encodes the specified string with GBK as a byte sequence
str = strcom.getbytes ("GBK");
for (int i = 0; i < str.length; i++) {//Output return array
System.out.println (Str[i]);
}
} catch (Unsupportedencodingexception e) {
E.printstacktrace ();
}
The difference between Collection and collections |, the GetBytes method of string