Java數(shù)組中的元素刪除并實(shí)現(xiàn)向前移的代碼
更新時(shí)間:2016年05月04日 14:48:19 作者:java
這篇文章主要介紹了Java數(shù)組中的元素刪除并實(shí)現(xiàn)向前移的代碼的相關(guān)資料,需要的朋友可以參考下
廢話不多說了,直接給大家貼代碼了。
具體代碼如下所示:
public class Test { /** * Java怎么刪除數(shù)組中的一個(gè)元素并且向前移 * * @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ì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11SpringBoot中的配置文件加載優(yōu)先級(jí)詳解
這篇文章主要介紹了SpringBoot中的配置文件加載優(yōu)先級(jí)詳解,springboot啟動(dòng)會(huì)掃描以下位置的application.properties或者application.yml文件作為Spring?boot的默認(rèn)配置文件,需要的朋友可以參考下2024-01-01Java中List根據(jù)map的某個(gè)key去重的代碼
今天小編就為大家分享一篇關(guān)于Java中List根據(jù)map的某個(gè)key去重的代碼,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-12-12解決mapstruct在eclipse生成不了mapper的實(shí)現(xiàn)類問題
這篇文章主要介紹了解決mapstruct在eclipse生成不了mapper的實(shí)現(xiàn)類問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11