I'm using a TreeList to store data. The key is a String and the value is an ArrayList<String>.
The source of the ArrayList is an array because the ArrayList members have to be sorted.
I created the following test code:
When I compile my sample:
Step 4 yields the following warning:
^
Step 7 yields the following warning:
Can anyone explain why I get these warnings and what I can to do eliminate them?
Thanks.
The source of the ArrayList is an array because the ArrayList members have to be sorted.
I created the following test code:
Code:
TreeMap<String, ArrayList> dataObjects = new TreeMap<String, ArrayList>();
ArrayList<String> fieldArrayList;
TreeMap<String, ArrayList> dataObjects = new TreeMap<String, ArrayList>();
ArrayList<String> fieldArrayList;
// 1. Create a String array that will be sorted
String [] fieldArray = new String[3];
fieldArray[0] = "omar";
fieldArray[1] = "philippe";
fieldArray[2] = "hua";
// 2. Sort the array
Arrays.sort(fieldArray);
// 3. Turn the array into a java.util.List so the ArrayList constructor will accept it
List fieldList = Arrays.asList(fieldArray);
// 4. Make the ArrayList
fieldArrayList = new ArrayList<String>( fieldList);
// 5. Put the ArrayList into the TreeMap
dataObjects.put("Friends", fieldArrayList);
// 6. Print contents of the TreeMap
for ( Map.Entry t: dataObjects.entrySet() )
{
System.out.println( t.getKey() );
// 7. Get the ArrayList from the TreeMap entry
ArrayList<String> list = (ArrayList<String>) t.getValue();
for (String name : list )
{
System.out.println(list);
}
}
When I compile my sample:
Step 4 yields the following warning:
Code:
warning: [unchecked] unchecked conversion
found : java.util.List
required: java.util.Collection<? extends java.lang.String>
fieldArrayList = new ArrayList<String>( fieldList);
Step 7 yields the following warning:
Code:
warning: [unchecked] unchecked cast
found : java.lang.Object
required: java.util.ArrayList<java.lang.String>
ArrayList<String> list = (ArrayList<String>) t.getValue();
Can anyone explain why I get these warnings and what I can to do eliminate them?
Thanks.