I am trying to get the index of the lowest value in a array/ArrayList. How do I do this?

I have an array of length 4(which I can make an ArrayList if that would be easier), and I need to find the index of the lowest value in the array, to remove that same index from an ArrayList.
17 Replies
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @blockgoblin31! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
no it isnt
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
like this?
if (equippedTrinkets.size() > 3) {
List<Integer> stats = new List<>();
for (int j = 0; j < equippedTrinkets.size(); j++) {
stats.add(this.equippedTrinkets.get(j).bonus);
}
int temp = 0;
for (int k : stats) {
if (k < temp) temp = k;
}
equippedTrinkets.remove(stats.indexOf(temp));
}
if (equippedTrinkets.size() > 3) {
List<Integer> stats = new List<>();
for (int j = 0; j < equippedTrinkets.size(); j++) {
stats.add(this.equippedTrinkets.get(j).bonus);
}
int temp = 0;
for (int k : stats) {
if (k < temp) temp = k;
}
equippedTrinkets.remove(stats.indexOf(temp));
}
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
thats what I thought I was doing(except the traditional for loop part) I was going through each value in the array, checking if it was lowest so far, and if so saving it then at the end getting the index of that in the list
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
the last line is getting that, with stats.indexOf(temp) at least I thought
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
yes, I'm getting the index of that value with .indexOf
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
yes
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
cool thanks
JavaBot
JavaBot2y ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot2y ago
Post Closed
This post has been closed by <@501514065068294154>.
Want results from more Discord servers?
Add your server