• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

Java Equivalent to VB Collection Initializers

VB.NET Java
'List:
Dim myList As New List(Of Integer)() From {1, 2, 3}

'Dictionary:
Dim myD As New Dictionary(Of String, Integer) From {
    {string1, 80},
    {string2, 85}
}
import java.util.*;

//ArrayList: (Java 9 List.of would also work here)
ArrayList<Integer> myList = new ArrayList<Integer>(Arrays.asList(1, 2, 3));

//HashMap: (Map.ofEntries requires Java 9)
HashMap<String, Integer> myD = new HashMap<String, Integer>(Map.ofEntries(Map.entry(string1, 80), Map.entry(string2, 85)));


Use VB to Java Converter to convert from VB to Java.     

Additional resource: VB.NET and Java Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.