Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Edmunds Žagars
Java_course_final
Commits
9671cc23
Commit
9671cc23
authored
Mar 05, 2018
by
edmundszagars
Browse files
Fixing "getDataFromCSV" to return correct data type
parent
0f528cdd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
5 deletions
+8
-5
data2.csv
data2.csv
+2
-0
src/GetDataFromCSV.java
src/GetDataFromCSV.java
+4
-4
src/Main.java
src/Main.java
+2
-1
No files found.
data2.csv
0 → 100644
View file @
9671cc23
1, 2, 3
1, 2, 3, 4
\ No newline at end of file
src/GetDataFromCSV.java
View file @
9671cc23
...
...
@@ -8,21 +8,21 @@ import java.util.Scanner;
public
class
GetDataFromCSV
{
private
String
nFileLocation
=
"data.csv"
;
public
ArrayList
getDataFromCSV
()
throws
FileNotFoundException
{
public
List
<
ArrayList
<
Double
>>
getDataFromCSV
()
throws
FileNotFoundException
{
List
<
ArrayList
<
Double
>>
nListOfValues
=
new
ArrayList
<>();
Scanner
scanner
=
new
Scanner
(
new
BufferedReader
(
new
FileReader
(
nFileLocation
)));
while
(
scanner
.
hasNextLine
()){
while
(
scanner
.
hasNextLine
())
{
String
nLine
=
scanner
.
nextLine
();
String
[]
inArray
=
nLine
.
split
(
","
);
ArrayList
<
Double
>
list
=
new
ArrayList
<>();
for
(
String
anInArray
:
inArray
)
{
list
.
add
(
Double
.
parseDouble
(
anInArray
));
}
if
(
list
.
size
()
!=
0
){
if
(
list
.
size
()
!=
0
)
{
nListOfValues
.
add
(
list
);
}
}
return
(
ArrayList
)
nListOfValues
;
return
nListOfValues
;
}
public
void
setnFileLocation
(
String
nFileLocation
)
{
...
...
src/Main.java
View file @
9671cc23
...
...
@@ -4,7 +4,8 @@ import java.util.Arrays;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
GetDataFromCSV
get
=
new
GetDataFromCSV
();
get
.
setnFileLocation
(
"data2.csv"
);
for
(
int
i
=
0
;
i
<
get
.
getDataFromCSV
().
size
();
i
++)
System
.
out
.
println
(
get
.
getDataFromCSV
().
get
(
i
));
System
.
out
.
println
(
get
.
getDataFromCSV
().
get
(
i
)
.
size
()
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment