Hello there, I want to delete a line out of an arraylist if it contains something, i already tried some things but it didnt work, can you help me? Bye, Bart
Create a numeric for loop that iterated through your arraylist, get the string using the index, check it and delete the string at the index when it should be.
This is quite simple to do, First get the List from the config onto a List object, then remove the unneeded entry. Then set the new List to the path of the arraylist in the config. Hope this solves your question.
Well what have you tried so far? This should work. Code (Text): List<String> yourList = new ArrayList<String>(); if(yourList.size() != 0) { for (String s : yourList) { if (s.equalsIgnoreCase("your String")) { yourList.remove(s); } } }
It doesnt work, what i tried (invc is a config): Code (Text): List<String> list = invc.getStringList(defaultpath); String c = ","; if(list.contains(isclaiming.get(p))){ for(int x = 0; x < list.size(); x++){ String s = list.get(x); if(s.contains(isclaiming.get(p))){ list.remove(x); } } }
Try this (and don't forget setting the updated list into the config at the end as well as saving it) Code (Text): List<String> list = invc.getStringList(defaultpath); HashMap<String, Player> isclaiming = new HashMap<String, Player>(); if(list.contains(isclaiming.get(player))) { for(String s : list) { if(s.contains(isclaiming.get(player))) { list.remove(s); } invc.set(defaultpath, list); invc.saveConfig(); } }
..... what about a simpler way like this.... Code (Text): List<String> list = invc.getStringList(defaultpath); String c = ","; if(list.contains(isclaiming.get(p).getName())){ list.remove(isclaiming.get(p).getName()); } invc.set(defaultpath,list); invc.save();
It isnt about player names but about strings, isclaming is a hasmap <Player, String> Thanks it worked now!