It is necessary that I create a String[]
with 5 strings, each of these strings carries multiple substrings with data separated by commas, I must convert this array of int into ArrayList
to section the sub strings in this order: the numbers '1, 2, 3, 4, 5' are student ID numbers. 'john, suzan, jack, erin, adan' are first names, etc.. However, the only issue I ran into is when I'm trying to print the array of grades, ex: '88, 79, 59' into an ArrayList
object that prints: 887959(1 arraylist object), NOT 88 (1 arraylist object), 79(another arraylist object),...
What am I doing wrong? How do I fix this?
Code:
String[] kaizer =
{
"1,John,Smith,[email protected],20,88,79,59",
"2,Suzan,Erickson,Erickson_1990@gmailcom,19,91,72,85",
"3,Jack,Napoli,The_lawyer99yahoo.com,19,85,84,87",
"4,Erin,Black,[email protected],22,91,98,82",
"5,Adan,Ramirez,[email protected],23,100,100,100"
};
ArrayList<Integer> grades = new ArrayList<Integer>();
for (int i = 0; i < kaizer.length; i++) {
String s = kaizer[i]; //volatile reference
String[] parts = s.split(",");
//volatile reference
String id = parts[0];
String name = parts[1];
String lastname = parts[2];
String email = parts[3];
String age = parts[4];
grades.add(Integer.parseInt(parts[5]));
grades.add(Integer.parseInt(parts[6]));
grades.add(Integer.parseInt(parts[7]));
//Widget w = new Widget(id, name, num);
//mywidgets.add(w);
}
This is supposed to print the set of substrings like this:
887959
917285
858487
919882
100100100
System.out.println(grades.get(0));
System.out.println(grades.get(1));
System.out.println(grades.get(2));
System.out.println(grades.get(3));
System.out.println(grades.get(4));
Instead... it prints:
8879599172
The problem lies in the output: '8879599172'
List<Student>
where theStudent
data is obtained after parsing eachString
. – Luiggi Mendoza Aug 31 '15 at 14:30main()
as the only method. – PM 77-1 Aug 31 '15 at 14:31