public class SuperArray {
private int[] array;
private int currentIndex = -1;
public SuperArray(int size){
array=new int[size];
}
public SuperArray(){
this(10);
}
public void sort(){
for (int i=0;i<currentIndex;i++){
for(int j=0;j<currentIndex-i;j++){
if(array[j]>array[j+1]){
int temp = array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
}
public SuperArray add(int data){
currentIndex++;
if(currentIndex>=array.length){
int[] temp =new int[array.length * 2];
for(int i=0;i<array.length;i++){
temp[i]=array[i];
}
array =temp;
}
array[currentIndex]=data;
return this;
}
public void delete(int index){
if(index<0 || index>currentIndex) return;
for(int i=index;i<currentIndex;i++){
array[i]=array[i+1];
}
currentIndex--;
}
public void print(){
for(int i=0;i<=currentIndex;i++){
System.out.print(array[i]+" ");
}
}
public String arrayToStr(){
String res = "";
for(int i=0;i<=currentIndex;i++){
if(i==currentIndex){
res+=array[i];
}else{
res+=array[i]+",";
}
}
return res;
}
public static void main(String[] args) {
SuperArray superArray = new SuperArray(2);
superArray.add(1).add(2).add(3).add(1).add(2).add(3);
System.out.println(superArray.arrayToStr());
}
}
map的遍历方式:用Map.entry!
public class Arithmitic {
public static void main(String[] args) {
String cw ="haha haha hhh Ha Ha" +"aa bb AA bb bb dd";
String s = cw.toLowerCase();
String[] words =s.split(" ");
HashMap<String,Integer> map =new HashMap<>();
for (String word : words){
if(map.containsKey(word)){
map.put(word,map.get(word)+1);
}else {
map.put(word,1);
}
}
for (Map.Entry<String,Integer> entry : map.entrySet()){
System.out.println(entry.getKey()+" appeared "+entry.getValue()+"times");
}
}
}