Skip to content
Advertisement

Tag: arraylist

Remove Alternate Elements from ArrayList in java 7

I have an array of String containing below elements Now what I want to do I need to remove all the decimal value in string format like 5.0,5.5 and 6.0 so my final array should contain elements 99,100,101 so what I’d done so far is show in below code I have hardcoded the values which is quite bad practice as

Setting object attributes via a array list

Basically I am working on a project where certain class attributes and names of classes are stored in a text file. The goal here is to create a list of the objects of a certain data type (in this case Car) listed in the text file (of which I have already done), and then assign these to the data types

Difference between Arraylist.forEach() and Arraylist.replaceAll()

I have a question about the difference between Arraylist.forEach() and Arraylist.replaceAll(). I know that Arraylist.forEach() is used to perform an action for each element in the list, but it seems that Arraylist.replaceAll() does the exact same thing. But for some reason, when you decide to do a.forEach(e -> e.concat(“test”); assuming a is an Arraylist of Strings, the Arraylist does not

Android studio can’t find ArrayList class

First of all I’ve been using Android studio for quite years but this has never happened before. It seems like android studio’s inner ArrayList class has vanished out of a sudden. I can’t use ArrayList. It always says Can’t find symbol ArrayList I’ve cleaned rebuild and even invalidated caches and restarted several times but all in vain. My android studio

Deleting an item (index) from SharedPreferences

I’m saving an array called semesterArray which is a List<String> semesterArray = new ArrayList<>() with the following method on SharedPreferences: The if statement is there to update the SharedPreferences, I got the idea from this StackOverflow answer. Now, the following method takes care of loading the SharedPreferences that were just saved: We remove duplicate Semesters because the if statement in

How can I make SharedPreferences to update the data instead of overwriting the data and losing part of it?

I’m using the following piece of code to save an ArrayList<String> into SharedPreferences: This is somewhat getting the job done since it saves the ArrayList<String> as intended and when the app is re-launched the Semesters that were added are still stored in the ArrayList<String> as I want them to be. But if I add more Semesters after re-launching the app,

Backward Traverse using ListIteartor in java

I am new to java and learning from a very basic level. I am trying to run this below code which is not showing any result in the console. It’s only working when I add forward traverse code before it. Can anyone please help me with that? Thanks Answer When you create a list iterator with a call to myList.listIterator(),

Advertisement