Java數(shù)組中的元素刪除并實(shí)現(xiàn)向前移的代碼
更新時間:2016年05月04日 14:48:19 作者:java
這篇文章主要介紹了Java數(shù)組中的元素刪除并實(shí)現(xiàn)向前移的代碼的相關(guān)資料,需要的朋友可以參考下
廢話不多說了,直接給大家貼代碼了。
具體代碼如下所示:
public class Test { /** * Java怎么刪除數(shù)組中的一個元素并且向前移 * * @param args * @throws IOException */ public static void main(String[] args) { String[] arrays = { "", "", "", "", "" }; System.out.println("數(shù)組刪除前:"); for (int i = ; i < arrays.length; i++) { System.out.print(arrays[i]+" "); } String[] arrays =removeitem(arrays,""); System.out.println(""); System.out.println("數(shù)組刪除后:"); for (int i = ; i < arrays.length; i++) { System.out.print(arrays[i]+" "); } } public static String[] removeitem(String[] arrays,String str){ String[] tempArr = new String[arrays.length]; int i = ; for(String s:arrays){ if(!s.equals(str)){ tempArr[i] = s; i++; } } return tempArr; } }
相關(guān)文章
SpringBoot整合Gson 整合Fastjson的實(shí)例詳解
這篇文章主要介紹了SpringBoot整合Gson 整合Fastjson的實(shí)例詳解,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-11-11解決mapstruct在eclipse生成不了mapper的實(shí)現(xiàn)類問題
這篇文章主要介紹了解決mapstruct在eclipse生成不了mapper的實(shí)現(xiàn)類問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11