using split() method in an arraylist object the code is incompleteCreate ArrayList from arrayWhen to use LinkedList over ArrayList in Java?Initialization of an ArrayList in one lineSort ArrayList of custom Objects by propertyHow to avoid Java code in JSP files?How to split a string in JavaConverting 'ArrayList<String> to 'String[]' in JavaConvert ArrayList<String> to String[] arrayWhy does this code using random strings print “hello world”?Why is executing Java code in comments with certain Unicode characters allowed?
Does science define life as "beginning at conception"?
How do we explain the use of a software on a math paper?
why "American-born", not "America-born"?
Is there a word for pant sleeves?
If the Charles SSL Proxy shows me sensitive data, is that data insecure/exposed?
Is there a realtime, uncut video of Saturn V ignition through tower clear?
Separate the element after every 2nd ',' and push into next row in bash
Does George B Sperry logo on fold case for photos indicate photographer or case manufacturer?
Way of refund if scammed?
Don't understand notation of morphisms in Monoid definition
How to become an Editorial board member?
Why does an injection from a set to a countable set imply that set is countable?
What's is the easiest way to purchase a stock and hold it
How should I mix small caps with digits or symbols?
How do you cope with rejection?
Story about encounter with hostile aliens
Good examples of "two is easy, three is hard" in computational sciences
Why "strap-on" boosters, and how do other people say it?
How to play vs. 1.e4 e5 2.Nf3 Nc6 3.Bc4 d6?
How to prove the emptiness of intersection of two context free languages is undecidable?
What quantum phenomena violate the superposition principle in electromagnetism?
Germany rejected my entry to Schengen countries
Existence of a model of ZFC in which the natural numbers are really the natural numbers
Why use nominative in Coniugatio periphrastica passiva?
using split() method in an arraylist object the code is incomplete
Create ArrayList from arrayWhen to use LinkedList over ArrayList in Java?Initialization of an ArrayList in one lineSort ArrayList of custom Objects by propertyHow to avoid Java code in JSP files?How to split a string in JavaConverting 'ArrayList<String> to 'String[]' in JavaConvert ArrayList<String> to String[] arrayWhy does this code using random strings print “hello world”?Why is executing Java code in comments with certain Unicode characters allowed?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
public static void main(String[] args) throws Exception
File inputFile = new File("input.txt");
Scanner read = new Scanner(inputFile);
File outputFile = new File("output.txt");
PrintWriter print = new PrintWriter(outputFile);
if (!inputFile.exists())
System.out.println("File does not exist!");
ArrayList<Event> myArray = new ArrayList<>();
String commands="";
while (read.hasNext())
if(commands.matches("AddMovie"))
addMovie(read);
print.flush();
print.close();
read.close();
//java netbeans
public static Event addMovie(Scanner in)
String m[]=new String[6];
for (int i = 0; i < m.length; i++)
String name=in.next();
Date sDate=new Date(in.next());
Date eDate=new Date(in.next());
double price=in.nextDouble();
String city=in.next();
String address=in.next();
String language=in.next();
String tAudience=in.next();
double raiting=in.nextDouble();
int tickets=in.nextInt();
return movie;
well I am having a problem here so my program must read from a file these given data
AddMovie--The Upside, 6/3/2019, 6/6/2019, 50, Riyadh, Al Qasr Mall, English, Family, 4.5, 40, Comedy, Nicole Kidman, F, 1967
I have to store them in an ArrayList of object and I have to use non-word characters as a delimiter to split these data should I make a method and inside this method a 1-dimensional array and then use split() method?
java
add a comment |
public static void main(String[] args) throws Exception
File inputFile = new File("input.txt");
Scanner read = new Scanner(inputFile);
File outputFile = new File("output.txt");
PrintWriter print = new PrintWriter(outputFile);
if (!inputFile.exists())
System.out.println("File does not exist!");
ArrayList<Event> myArray = new ArrayList<>();
String commands="";
while (read.hasNext())
if(commands.matches("AddMovie"))
addMovie(read);
print.flush();
print.close();
read.close();
//java netbeans
public static Event addMovie(Scanner in)
String m[]=new String[6];
for (int i = 0; i < m.length; i++)
String name=in.next();
Date sDate=new Date(in.next());
Date eDate=new Date(in.next());
double price=in.nextDouble();
String city=in.next();
String address=in.next();
String language=in.next();
String tAudience=in.next();
double raiting=in.nextDouble();
int tickets=in.nextInt();
return movie;
well I am having a problem here so my program must read from a file these given data
AddMovie--The Upside, 6/3/2019, 6/6/2019, 50, Riyadh, Al Qasr Mall, English, Family, 4.5, 40, Comedy, Nicole Kidman, F, 1967
I have to store them in an ArrayList of object and I have to use non-word characters as a delimiter to split these data should I make a method and inside this method a 1-dimensional array and then use split() method?
java
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kozmo
Mar 23 at 19:39
Please share the code that you've tried with so far.
– Mick Mnemonic
Mar 23 at 19:40
add a comment |
public static void main(String[] args) throws Exception
File inputFile = new File("input.txt");
Scanner read = new Scanner(inputFile);
File outputFile = new File("output.txt");
PrintWriter print = new PrintWriter(outputFile);
if (!inputFile.exists())
System.out.println("File does not exist!");
ArrayList<Event> myArray = new ArrayList<>();
String commands="";
while (read.hasNext())
if(commands.matches("AddMovie"))
addMovie(read);
print.flush();
print.close();
read.close();
//java netbeans
public static Event addMovie(Scanner in)
String m[]=new String[6];
for (int i = 0; i < m.length; i++)
String name=in.next();
Date sDate=new Date(in.next());
Date eDate=new Date(in.next());
double price=in.nextDouble();
String city=in.next();
String address=in.next();
String language=in.next();
String tAudience=in.next();
double raiting=in.nextDouble();
int tickets=in.nextInt();
return movie;
well I am having a problem here so my program must read from a file these given data
AddMovie--The Upside, 6/3/2019, 6/6/2019, 50, Riyadh, Al Qasr Mall, English, Family, 4.5, 40, Comedy, Nicole Kidman, F, 1967
I have to store them in an ArrayList of object and I have to use non-word characters as a delimiter to split these data should I make a method and inside this method a 1-dimensional array and then use split() method?
java
public static void main(String[] args) throws Exception
File inputFile = new File("input.txt");
Scanner read = new Scanner(inputFile);
File outputFile = new File("output.txt");
PrintWriter print = new PrintWriter(outputFile);
if (!inputFile.exists())
System.out.println("File does not exist!");
ArrayList<Event> myArray = new ArrayList<>();
String commands="";
while (read.hasNext())
if(commands.matches("AddMovie"))
addMovie(read);
print.flush();
print.close();
read.close();
//java netbeans
public static Event addMovie(Scanner in)
String m[]=new String[6];
for (int i = 0; i < m.length; i++)
String name=in.next();
Date sDate=new Date(in.next());
Date eDate=new Date(in.next());
double price=in.nextDouble();
String city=in.next();
String address=in.next();
String language=in.next();
String tAudience=in.next();
double raiting=in.nextDouble();
int tickets=in.nextInt();
return movie;
well I am having a problem here so my program must read from a file these given data
AddMovie--The Upside, 6/3/2019, 6/6/2019, 50, Riyadh, Al Qasr Mall, English, Family, 4.5, 40, Comedy, Nicole Kidman, F, 1967
I have to store them in an ArrayList of object and I have to use non-word characters as a delimiter to split these data should I make a method and inside this method a 1-dimensional array and then use split() method?
public static void main(String[] args) throws Exception
File inputFile = new File("input.txt");
Scanner read = new Scanner(inputFile);
File outputFile = new File("output.txt");
PrintWriter print = new PrintWriter(outputFile);
if (!inputFile.exists())
System.out.println("File does not exist!");
ArrayList<Event> myArray = new ArrayList<>();
String commands="";
while (read.hasNext())
if(commands.matches("AddMovie"))
addMovie(read);
print.flush();
print.close();
read.close();
//java netbeans
public static Event addMovie(Scanner in)
String m[]=new String[6];
for (int i = 0; i < m.length; i++)
String name=in.next();
Date sDate=new Date(in.next());
Date eDate=new Date(in.next());
double price=in.nextDouble();
String city=in.next();
String address=in.next();
String language=in.next();
String tAudience=in.next();
double raiting=in.nextDouble();
int tickets=in.nextInt();
return movie;
public static void main(String[] args) throws Exception
File inputFile = new File("input.txt");
Scanner read = new Scanner(inputFile);
File outputFile = new File("output.txt");
PrintWriter print = new PrintWriter(outputFile);
if (!inputFile.exists())
System.out.println("File does not exist!");
ArrayList<Event> myArray = new ArrayList<>();
String commands="";
while (read.hasNext())
if(commands.matches("AddMovie"))
addMovie(read);
print.flush();
print.close();
read.close();
//java netbeans
public static Event addMovie(Scanner in)
String m[]=new String[6];
for (int i = 0; i < m.length; i++)
String name=in.next();
Date sDate=new Date(in.next());
Date eDate=new Date(in.next());
double price=in.nextDouble();
String city=in.next();
String address=in.next();
String language=in.next();
String tAudience=in.next();
double raiting=in.nextDouble();
int tickets=in.nextInt();
return movie;
java
java
edited Mar 24 at 3:21
skomisa
7,17642448
7,17642448
asked Mar 23 at 19:38
J.AJ.A
12
12
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kozmo
Mar 23 at 19:39
Please share the code that you've tried with so far.
– Mick Mnemonic
Mar 23 at 19:40
add a comment |
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kozmo
Mar 23 at 19:39
Please share the code that you've tried with so far.
– Mick Mnemonic
Mar 23 at 19:40
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kozmo
Mar 23 at 19:39
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kozmo
Mar 23 at 19:39
Please share the code that you've tried with so far.
– Mick Mnemonic
Mar 23 at 19:40
Please share the code that you've tried with so far.
– Mick Mnemonic
Mar 23 at 19:40
add a comment |
2 Answers
2
active
oldest
votes
From what I can understand you are on the right track. Given you read the data you have provided as one single string, you can use the split(",") method on it and store the result of that into an array of strings.
so i can use an array of string to split data and then store them in arrayList of object?
– J.A
Mar 23 at 19:49
Well, the split() method produces an array of strings, which could be then converted to an ArrayList object.
– RaMb3asT
Mar 23 at 19:55
add a comment |
I think that splitting on 'non-word characters' would not be a good idea, as for example you would not want 4.5 to be split into 4 and 5.
I would probably split on ','.
If you were worried about efficiency, it would be a good idea to create a java.util.regex.Pattern object with (for e.g.)
Pattern pat = Pattern.compile(",");
then whenever you wanted to use it, using:
pat.split(theString);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317627%2fusing-split-method-in-an-arraylist-object-the-code-is-incomplete%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
From what I can understand you are on the right track. Given you read the data you have provided as one single string, you can use the split(",") method on it and store the result of that into an array of strings.
so i can use an array of string to split data and then store them in arrayList of object?
– J.A
Mar 23 at 19:49
Well, the split() method produces an array of strings, which could be then converted to an ArrayList object.
– RaMb3asT
Mar 23 at 19:55
add a comment |
From what I can understand you are on the right track. Given you read the data you have provided as one single string, you can use the split(",") method on it and store the result of that into an array of strings.
so i can use an array of string to split data and then store them in arrayList of object?
– J.A
Mar 23 at 19:49
Well, the split() method produces an array of strings, which could be then converted to an ArrayList object.
– RaMb3asT
Mar 23 at 19:55
add a comment |
From what I can understand you are on the right track. Given you read the data you have provided as one single string, you can use the split(",") method on it and store the result of that into an array of strings.
From what I can understand you are on the right track. Given you read the data you have provided as one single string, you can use the split(",") method on it and store the result of that into an array of strings.
answered Mar 23 at 19:46
RaMb3asTRaMb3asT
2118
2118
so i can use an array of string to split data and then store them in arrayList of object?
– J.A
Mar 23 at 19:49
Well, the split() method produces an array of strings, which could be then converted to an ArrayList object.
– RaMb3asT
Mar 23 at 19:55
add a comment |
so i can use an array of string to split data and then store them in arrayList of object?
– J.A
Mar 23 at 19:49
Well, the split() method produces an array of strings, which could be then converted to an ArrayList object.
– RaMb3asT
Mar 23 at 19:55
so i can use an array of string to split data and then store them in arrayList of object?
– J.A
Mar 23 at 19:49
so i can use an array of string to split data and then store them in arrayList of object?
– J.A
Mar 23 at 19:49
Well, the split() method produces an array of strings, which could be then converted to an ArrayList object.
– RaMb3asT
Mar 23 at 19:55
Well, the split() method produces an array of strings, which could be then converted to an ArrayList object.
– RaMb3asT
Mar 23 at 19:55
add a comment |
I think that splitting on 'non-word characters' would not be a good idea, as for example you would not want 4.5 to be split into 4 and 5.
I would probably split on ','.
If you were worried about efficiency, it would be a good idea to create a java.util.regex.Pattern object with (for e.g.)
Pattern pat = Pattern.compile(",");
then whenever you wanted to use it, using:
pat.split(theString);
add a comment |
I think that splitting on 'non-word characters' would not be a good idea, as for example you would not want 4.5 to be split into 4 and 5.
I would probably split on ','.
If you were worried about efficiency, it would be a good idea to create a java.util.regex.Pattern object with (for e.g.)
Pattern pat = Pattern.compile(",");
then whenever you wanted to use it, using:
pat.split(theString);
add a comment |
I think that splitting on 'non-word characters' would not be a good idea, as for example you would not want 4.5 to be split into 4 and 5.
I would probably split on ','.
If you were worried about efficiency, it would be a good idea to create a java.util.regex.Pattern object with (for e.g.)
Pattern pat = Pattern.compile(",");
then whenever you wanted to use it, using:
pat.split(theString);
I think that splitting on 'non-word characters' would not be a good idea, as for example you would not want 4.5 to be split into 4 and 5.
I would probably split on ','.
If you were worried about efficiency, it would be a good idea to create a java.util.regex.Pattern object with (for e.g.)
Pattern pat = Pattern.compile(",");
then whenever you wanted to use it, using:
pat.split(theString);
answered Mar 23 at 19:50
Bill NaylorBill Naylor
7117
7117
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317627%2fusing-split-method-in-an-arraylist-object-the-code-is-incomplete%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kozmo
Mar 23 at 19:39
Please share the code that you've tried with so far.
– Mick Mnemonic
Mar 23 at 19:40