If a string of characters such as "aaaabbc China 1512" To count the number of English characters , Number of Chinese characters , And the number of numeric characters , Assume that there are no Chinese characters in the characters , English characters , Special characters other than numeric characters .
int engishCount; int chineseCount; int digitCount; for(int
i=0;i<str.length;i++) { char ch = str.charAt(i); if(ch>=’0’ && ch<=’9’) {
digitCount++ } else if((ch>=’a’ && ch<=’z’) || (ch>=’A’ && ch<=’Z’)) {
engishCount++; } else { chineseCount++; } } System.out.println(……………);
How to check that a string contains only numbers ?

 

One , use JAVA Built in function

Two , Using regular expressions

Three , use ascii Code judgment

 

Java How to use generics to write a LRU cache ?

 

This is a hybrid data structure , We need to build a linked list based on the hash table . however Java This form of data structure has been provided for us -LinkedHashMap! It even provides a way to override the recycling policy . The only thing we need to pay attention to is this , The order of changing the linked list is the order of insertion , Not the order of access . however , There is a constructor that provides an option , You can use the order of access .
import java.util.LinkedHashMap; import java.util.Map; public LRUCache<K, V>
extends LinkedHashMap<K, V> {   private int cacheSize;   public LRUCache(int
cacheSize) {     super(16, 0.75, true);     this.cacheSize = cacheSize;   }
  protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {     return
size() >= cacheSize;   } }
Write a paragraph Java The program will byte Convert to long?
/**      * utilize {@link java.nio.ByteBuffer} realization byte[] turn long      * @param input
     * @param offset      * @param littleEndian Is the input array in small end mode      * @return
     */     public static long bytesToLong(byte[] input, int offset, boolean
littleEndian) {         // take byte[] Packaged as ByteBuffer         ByteBuffer buffer =
ByteBuffer.wrap(input,offset,8);         if(littleEndian){             //
ByteBuffer.order(ByteOrder) Method to specify the byte order , That is, the large and small end mode (BIG_ENDIAN/LITTLE_ENDIAN)
            // ByteBuffer The default is big end (BIG_ENDIAN) pattern
            buffer.order(ByteOrder.LITTLE_ENDIAN);         }         return
buffer.getLong();       }
When not in use StringBuffer Under the premise of , How to reverse a string ?
String str=in.nextLine(); char str1[]; char[] chrCharArray;
// Create an array of characters chrCharArray chrCharArray = str.toCharArray();// Converts a string variable to a character array int
len=str.length(); str1=new char[len]; for (int i =0,j=len-1; i < len&&j>=0;j--,
i++) {     str1[i]=chrCharArray[j]; } System.out.println(str1); str=
String.valueOf(str1 ); // Converts a character array to a string System.out.println(str);
Java in , How to get the highest frequency of words in a file ?

 
public static void main(String[] args) {         long start =
System.currentTimeMillis();         String str = "Look to the skies above
London and you'll see the usual suspects rainclouds, plane and pigeons. But by
the end of the year, you might just see something else.";         str =
str.replace('\'', ' ');// take ' Replace the number with a space         str = str.replace(',', '
');// Replace commas with spaces         str = str.replace('.', ' ');// Replace the period with a space         String[]
strings = str.split("\\s+");   // “\\s+” Represents one or more spaces , It's a regular expression //      String[]
strings = str.split(" +"); // “ +” It can also represent one or more spaces on my machine         Map<String,
Integer> map = new HashMap<String, Integer>();         List<String> list = new
ArrayList<String>();// Store every word that doesn't repeat         for(String s : strings){
            if(map.containsKey(s)){// If map The word is already included in , Then the number of them is counted +1                 int
x = map.get(s);                 x++;                 map.put(s, x);
            }else{  // If map There is no need to include the word in , Represents the first appearance of the word , Put it in the map And set the number to 1
                map.put(s, 1);
                list.add(s);// Add it to the list in , It means it's a new word             }         }
        int max=0;// Record the number of occurrences of the word with the most occurrences         String maxString =
null;// Record the value of the word with the most occurrences         /*          * from list Take each word from the list , stay map Find its occurrence times in
         * There's no real sort , Just record the word that appears most frequently          */         for(String s : list){
            int x = map.get(s);             if(x>max){
                maxString = s;                 max = x;             }         }
        System.out.println(maxString);         long end =
System.currentTimeMillis();         System.out.println(" Total time :" + (end - start) +
" millisecond ");     }
 

How to check that two given strings are in reverse order ?

Java in , How to print out all permutations of a string ?

Java in , How to print out repeated elements in an array ?

Java How to convert a string to an integer in ?

How to exchange the values of two integer variables without using temporary variables ?

Technology