• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 541
  • Last Modified:

Changing arraylist values

Hi Experts,

If I had a list of integers stored in an arraylist and wanted to change any integers value to 0 if it were above 10 how would I do this?
0
DColin
Asked:
DColin
2 Solutions
 
Julian HansenCommented:
The simple approach
Dim al As New ArrayList()
        al.Add(1)
        al.Add(21)
        al.Add(12)
        al.Add(7)
        For i = 0 To al.Count - 1
            If al(i) < 10 Then
                al(i) = 0
            End If
        Next

Open in new window

0
 
n2fcCommented:
' set n to number of elements in arrayList
For index As Integer = 1 To n
    If arrayList(index) > 10 Then 
        arrayList(index) = 0
    End If 
Next

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now