split() It can separate strings according to requirements and store them in the defined array

First encapsulate a Splits() Class to separate letters from numbers , Class name Splits();
public class Splits { private String s; public Splits(String s){ this.s = s; }
public Splits() { this("unknow"); } public String[] getStr(){ String[]
str_string = s.split("\\d");// \d Represent for regular expression [0-9] number return str_string; } public
int[] getNum(){ String[] num_string = s.split("\\D"); // \D Representing non numbers for regular expressions String
a = ""; for(String m : num_string){ a += m; } String[] num = a.split("");
// Save the detached data in a new array num Don't use it directly num_string,
Because when the regular expression selects a string, if the first few characters do not meet the requirements, but num_string Array will still have its position Is a space int[] inte = new
int[num.length]; for(int i =0; i < num.length; i++){ inte[i] =
Integer.parseInt(num[i]); // Store the numbers in the array int array } return inte; } // Printing letters in a string public
void printStr(){ String a = ""; for(String n : getStr()){ a += n; }
System.out.println(a); } // Print numbers in strings public void printNum(){ String a = "";
for(int n : getNum()){ a += n; } System.out.println(a); } }
Create an example :Demo()

Public class Demo{ <span style="white-space:pre"> </span>public static void
main(String[] args) { // TODO Auto-generated method stub Splits n1 = new
Splits("A1B2C3D4E5F6G7H8"); n1.printNum(); n1.printStr(); } } The operation results are as follows :

12345678 ABCDEFGH

©2019-2020 Toolsou All rights reserved,
JS How to operate java Realize the function of grabbing red packets C Language programming to find a student's grade The United Nations 《 Glory of Kings 》 Please go to the studio : To save the earth Dialogue between apple and Nissan suspended ,Apple Car How's it going ?CSS architecture design China's longest high speed rail officially opened ! The fastest way to finish the race 30.5 hour First knowledge MySQL Comprehensive review ( dried food )2021 year 1 Monthly programmer salary statistics , average 14915 element How to use it quickly html and css Write static page