Java????????????????
???????????? ???????[ 2015/1/13 11:47:50 ] ??????????????? java
????Q?????????????????????
????A:????????HashSet??HashMap??????????????TreeSet??TreeMap??????????????????ó??????????????????????С??????л????й????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????洢????????????????????Collections.sort(…)?????????????????????????洢?????????Ч????????????????????????????????е???????????????????????O(n)????????????????n???????????????n??С??????£?????O(n)???????????O??log n)?????????Ч?????????????????AMD???????????????Intel??????????????????н?????????????????????????????????????????????????????С????????????????????????????????????????????????????????????????????????????????
????Q????????????????????黹??????????????
????A???????????????????n????????????????????????O(log n)????????????????????O(n)???????????????????????????儷???????????O(n))????????б??????????????????????????????????????儷??????????????????????????????????????????????????????????????????????????????
??????????????????????????
????packagebigo;
????importjava.util.Arrays;
????publicclassInsertingElementsToArray{
????publicstaticvoidinsertUnsortedArray(StringtoInsert){
????String[]unsortedArray={"A"??"D"??"C"};
????String[]newUnsortedArray=newString[unsortedArray.length+1];
????System.arraycopy(unsortedArray??0??newUnsortedArray??0??3);
????newUnsortedArray[newUnsortedArray.length-1]=toInsert;
????System.out.println(Arrays.toString(newUnsortedArray));
????}
????publicstaticvoidmain(String[]args){
????insertUnsortedArray("B");
????}
????}
???????????????????????
????package bigo;
????import java.util.Arrays;
????public class InsertingElementsToArray {
????public static void insertSortedArray(String toInsert) {
????String[ ] sortedArray = { "A"?? "C"?? "D" };
????/*
????* Binary search returns the index of the search item
????* if found?? otherwise returns the minus insertion point. This example
????* returns index = -2?? which means the elemnt is not found and needs to
????* be inserted as a second element.
????*/
????int index = Arrays.binarySearch(sortedArray?? toInsert);
????if (index < 0) { // not found.
????// array indices are zero based. -2 index means insertion point of
????// -(-2)-1 = 1?? so insertIndex = 1
????int insertIndex = -index - 1;
????String[ ] newSortedArray = new String[sortedArray.length + 1];
????System.arraycopy(sortedArray?? 0?? newSortedArray?? 0?? insertIndex);
????System.arraycopy(sortedArray?? insertIndex??
????newSortedArray?? insertIndex + 1?? sortedArray.length - insertIndex);
????newSortedArray[insertIndex] = toInsert;
????System.out.println(Arrays.toString(newSortedArray));
????}
????}
????public static void main(String[ ] args) {
????insertSortedArray("B");
????}
????}
???????????????????????????????????????????????漸?????????????????/?????????????????????????????????洢??????????????????????????????????????????????????
????Q???????????????伯???
????A???????????Collections????????????????????????????????????
????public class ReadOnlyExample {
????public static void main(String args[ ]) {
????Set<string> set = new HashSet<string>( );
????set.add("Java");
????set.add("JEE");
????set.add("Spring");
????set.add("Hibernate");
????set = Collections.unmodifiableSet(set);
????set.add("Ajax"); // not allowed.
????}
????}
????Q????????????????????????е?LinkedHashSet????HashSet???????
????import java.util.ArrayList;
????import java.util.LinkedHashSet;
????import java.util.List;
????public class CollectionFunction {
????public <e> List<e> function (List <e> list) {
????return new ArrayList<e>(new LinkedHashSet<e>(list));
????}
????}
????A??????????????????????б???????LinkedHashSet????????????????????????LinkedHashSet??????????????????????????????????????????????LinkedHashSet??????HashSet???滻??
????Q??Java???????????Щ????????
????A??????????????????????????????????????С?????????????С?????????????????е?????????????????????????????????????????????????β?????????λ???????????????????????????????з?????????????????????????????????????????????????????翼??????????????????????????????????
??????????????????????????????????С??????п????????????????????????????????????????????С??
???????????????????????????磬???????Щ????£?LinkedList??????????????ArrayList???????????????????????
???????????:
????ArrayList list = new ArrayList(100);
?????????:
????// program to interface so that the implementation can change
????List list = new ArrayList(100);
????List list2 = new LinkedList(100);
????List emptyList = Collections.emptyList( );
????Set emptySet = Collections.emptySet( );
??????????б???????????????????????÷???????????0???????????飬?????????null???????????null???????????3??????????????????????????????????????null????????д????
????????ü?????????????????????????????????????????????????????????????????????????????????б????У?顣
?????????ЩJava?????????????????頂Core Java Career Essentials??????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11