Results 1 to 6 of 6
- 05-11-2011, 04:19 AM #1
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
Help with some errors in my program
I'm a new java student (currently in computer programming 101) I'm getting an error I've never seen before with this program...
import java.util.ArrayList;
public class Thirteen
{
public static void main (String[] args)
{
ArrayList nameList = new ArrayList();
nameList.add("James");
nameList.add("Catherine");
nameList.add("Bill");
for (int index = 0; index < nameList.size(); index++)
{
System.out.println("Index: " + index + "Name: " + nameList.get(index));
}
nameList.add(1, "Mary");
System.out.println("After the changes, " + "here are the items now:");
for (int index = 0; index < nameList.size(); index++)
{
System.out.println("Index: " + index + " Name: " + nameList.get(index));
}}}
I'm getting the error:
Note: Thirteen.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
can someone please explain this to me ... thank you
Sorry if this is in the wrong topic
- 05-11-2011, 04:27 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
That's not an error, it's a warning. If you wanna read the details google "java generics tutorial", short story, when you declare the array list do it like this
Notice the added parameter in between <>, this specifies the type the array list will hold.Java Code:ArrayList<String> varName = new ArrayList<String>();
- 05-11-2011, 04:54 AM #3
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
thanks a bunch.. quick response too :) !
- 05-11-2011, 04:55 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You are welcome, glad to have helped. Please mark your thread solved with the thread tools at the top.
- 05-11-2011, 05:05 AM #5
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
one more thing if you dont mind...
ArrayList<String> varName = new ArrayList<String>();
what do i replace string with if i want to use an array of integers?
- 05-11-2011, 05:08 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You can't use primitives for the type, you can however; use the wrapper class which has similar names to the primitive type. int would be Integer, double is Double, etc. Lookup autoboxing for more details.
Similar Threads
-
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
Errors with simple program... PLEASE HELP ME!!!
By maxpower1000sa in forum New To JavaReplies: 6Last Post: 05-03-2009, 11:55 PM -
Errors in Program (Right Triangle)
By SupaStudy in forum New To JavaReplies: 3Last Post: 03-26-2009, 10:42 AM -
Help with Errors in Inventory Program
By ljk8950 in forum AWT / SwingReplies: 3Last Post: 08-08-2008, 11:49 PM -
3 errors and then terminate program
By hezfast2 in forum New To JavaReplies: 2Last Post: 05-20-2008, 01:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks