I have the following javascript code var list = [ { Date : '2014-12-31 12:23:43', DateStart: '1980-12-30 23:43:42', Name: 'Kate', ... ... }, { Date : '1978-05-21 23:43:65', DateStart: '1973-04-06 12:34:09', Name: 'John', ... ... } ]; And the following code to verify for regex pattern: for (var i in list) { var data = []; if (/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/.test(list[i].?)) { data.push({ Data: list[i].Data }); } } What can I do to all columns be verified for the date pattern? Making the array date stay only with the values 2014-12-31 12:23:43,1980-12-30 23:43:42,1978-05-21 23:43:65,1973-04-06 12:34:09

Member Avatar
Member Avatar
+0 forum 2

Hi, Am trying to display all the items inside a ArrayList, but without using the cfloop. Could someone help me on this !!!! Its urgent.... Actually my issue is am trying to call a Javascript function within the loop of that arraylist. I can do that using Cfloop, but its not fullfill my requirement so am trying to execute that Arraylist without cfloop. I tried with cfscript but not sure how to call a javascript function within cfscript. Thanks Ashish

Member Avatar
Member Avatar
+0 forum 1

Hello, I've been trying to read txt from a file, and breaking each line into words and storing them in Array. Example. txt file C001 John Smith 999999 C002 Mary Agnes 888888 Here is my code. public class Customer implements iCommand{ static List<Customer> cust = new ArrayList<Customer>(); static private String cID, String cName, cPhonenum; public Customer(String id, String name, String phone_num){ this.cID = id; this.cName = name; this.cPhonenum = phone_num; } public static void main(String[] args){ Scanner f = null; try { f = new Scanner(new File("C:/x.txt")); } catch (FileNotFoundException e) { System.out.println("unable to open file"); e.printStackTrace(); } while (f.hasNextLine()){ …

Member Avatar
Member Avatar
+0 forum 2

I'm making a student system with console based java. I'm trying to load a text file's content to an ArrayList and later on search with a student registration number and list down his/her name and program. I'm having a hard time loading the text file contents in an ArrayList so that I can retrieve them later on as objects. I have made a search function that works perfectly on an Arraylist (Since when entering a new record I am putting them in ArrayList and they can be searched until the program is not shut) **This is the approach I am …

Member Avatar
Member Avatar
+0 forum 3

I have been learning about the collections namespace in C# so have been doing some little self-made projects to learn. I have made a car race app where you enter in the name, car and place of the racer this is then stored in an array list. I can extract the contents of my array list onto the console window but I would like to know how I can write and save it to a text file (kindof like a mini database). I know that every element stored in an array list is stored as an object therefore casting is …

Member Avatar
Member Avatar
+0 forum 5

If I have an array and an array list: int[] myArray = new int[2]; myArray[0] = 1; myArray[1] = 2; ArrayList myArrayList = new ArrayList(); myArrayList.Add("1st element"); myArrayList.AddRange(myArray); By calling the Addrange() method in myArrayList, does this add the contents of myArray to the second element of myArrayList? If so how do you access the second element of myArray through myArrayList?

Member Avatar
Member Avatar
+0 forum 4

for(int i = 0; i < program.size(); i++) if(program.get(i).contains(remp)) with the coding above, i can search and display all string in my arraylist that contains "hit2080". for example HIT2080___Introduction to Programming___ALL___Core___NULL___NULL HIT1307___Internet Technologies___ALL___Core___NULL___HIT2080 but i just want to search and display the first token that contains string "hit2080". Is there any way to get the first token?

Member Avatar
Member Avatar
+0 forum 8

I know with Lists you can instantiate them to an ArrayList, but is this generally a good idea? Is it better to do 'List<?> list = new ArrayList<?>();' rather then 'ArrayList<?> aList = new ArrayList<?>();'?

Member Avatar
Member Avatar
+0 forum 5

Hi I have been told that it is possible to call an ArrayList Method in a WebService from a console App. [Method] " public ArrayList AuthenticateUsers(string username, string password, string IncomingIP, decimal Pin) " [call] Service1 serv = new Service1(); ArrayList ar = serv.AuthenticateUsers("test", "12345","192.168.0.5", 29); Error Cannot implicitly convert type 'Object[] to System.Collections.ArrayList' how can i solve this? -G

Member Avatar
Member Avatar
+0 forum 2

Hello good afternoon. I have successfully serialized data in the past, however it seems as if I don;t fully understand the process. I have a class called ProgramState which stores a variable (called lastCreated) with custom class LinesProject and an ArrayList variable(called recentProjects) of this custom class. The purpose of these variables is to store the last created project as well as a list of five recently opened projects. Here is ProgramState: public class ProgramState implements Serializable{ private LinesProject lastCreated; private ArrayList<LinesProject> recentProjects; public ProgramState() { lastCreated=new LinesProject(); recentProjects=new ArrayList<LinesProject>(); } public ProgramState(LinesProject proj) { lastCreated=proj; recentProjects=new ArrayList<LinesProject>(); } //Setters …

Member Avatar
Member Avatar
+0 forum 3

So this is what i dit. Declared three classes: Main Term Polynom So in Polynom i try to call a "plus" method: i tried this: public Polynom add(Polynom pol){ Polynom res = new Polynom("",0); Term tox = new Term(0,0); for(Term p : Polynom){ for(Term other : pol.Polynom ){ if(p.getDeg()==other.getDeg()){ tox.setCoef(p.getCoef()+ other.getCoef()); tox.setDeg(p.getDeg()); } res.addTerm(tox); } } return res; } And I am facing a problem : I reffer to an object this and iam getting into an other object which is a this too. So when i try to add two polynoms I have wrong results. Is there a good …

Member Avatar
Member Avatar
+0 forum 1

Hi, I have a quick question. I am making a hang man game for project (I am at university as a computer science major), I have completed most of the game but have run into one small issue which has been given me a big problem. Right now I am using an ArrayList in conjunction with nested loops and methods to get the game done. Again the game is finished, there us just one issue which I am having. One of the requirments is that when the user inputs a letter, and the letter that is guessed mathches a letter(s) …

Member Avatar
Member Avatar
+0 forum 1

My assignment is to create a program that asks the user what they want to do: 1-add a member, 2-delete a member, 3-see the arraylist of members, or 4- exit. I have the menu popping up, but I can't get it to go back to the menu after I execute the program once. It needs to keep going until the user enters quit. I've tried everything I can think of. Help please? public class MemberList { public static void main(String[] args) { boolean cont = false; ArrayList<String> mymembers; mymembers = new ArrayList<String>(); String myS; double option; myS = JOptionPane.showInputDialog( null, …

Member Avatar
Member Avatar
+0 forum 2

Hi All, I have a question. Is adding/filling range numbers to an ArrayList possible in java?? Like this: {<12345, 13455>, <12745, 13755>, <2345, 2755>, <5345, 9455>, <2700, 5240>, <345, 13455>, <11345, 13000>} You can think of these like time segments. Here is the class to give you brief idea import java.util.ArrayList; import java.util.List; class Sector { int start; int end; public Sector(int start, int end) { this.start = start; this.end = end; } List<Sector> sectors = new ArrayList<Sector>(); for (int i = 0; i <7; i++) { } } }

Member Avatar
Member Avatar
+0 forum 2

I need help making this to display the results into a Jframe GUI instead of a console im failry new to java so please help me thanks, here is the code ive used: import java.util.ArrayList; public class ThreeArrayLists { public static void main(String[] args) { ArrayList priceList = new ArrayList(); ArrayList quantityList = new ArrayList(); ArrayList amountList = new ArrayList(); //PRICE lIST priceList.add(new Double(10.62)); priceList.add(new Double(14.89)); priceList.add(new Double(13.21)); priceList.add(new Double(16.55)); priceList.add(new Double(18.62)); priceList.add(new Double(9.47)); priceList.add(new Double(6.58)); priceList.add(new Double(18.32)); priceList.add(new Double(12.15)); priceList.add(new Double(3.98)); //QUANTITY LIST quantityList.add(new Double(4.0)); quantityList.add(new Double(8.5)); quantityList.add(new Double(6.0)); quantityList.add(new Double(7.35)); quantityList.add(new Double(9.0)); quantityList.add(new Double(15.3)); quantityList.add(new Double(3)); quantityList.add(new Double(5.4)); …

Member Avatar
Member Avatar
+0 forum 5

Hello. Im new here. I have a question: I have this copy constructor here: /** Copy Constructor. * Since landscape is immutable in the scope of our project, you could * do a simple reference copy for it. * However, Fish and Plants are mutable, so those lists must be copied * with a DEEP copy! * (In other words, each fish and each plant must be copied.) */ public Model(Model other) { landscape = other.landscape; fish = new ArrayList<Fish>(); for (Fish f : other.fish) { fish.add(new Fish(f)); } plants = new ArrayList<Plant>(); for (Plant p : other.plants){ plants.add(new Plant(p)); …

Member Avatar
Member Avatar
+0 forum 2

You will need to check that the four parameters entered by the user are blank, so you will do the same as you did before but four times. To Identify if the User Presses <enter> You have written a JAVA program that creates a CD object with four instance variables, along with a CDException.java class that helps you validate this input. So far you have been using these classes with my driver classes. Now it is time for you to create a real driver class that will implement an ArrayList of CD objects. Here is a list of requirements for …

Member Avatar
Member Avatar
+0 forum 1

Hey everyone, I want to add action listeners to JButtons that were created dynamically by an ArrayList. Here is the code for the button creation. numOfCourse = 6; courseBtnArray.add(new JButton("Course 1")); gbc.gridx = 2; for (int i = 0; i < numOfCourses; i++) { gbc.gridy++; add(courseBtnArray.get(i), gbc); courseBtnArray.add(new JButton("Course " + (i + 2))); } gbc.gridy++; add(courseBtnArray.get(courseBtnArray.size() - 1), gbc); System.out.println("the size of the textbox arraylist is:" + courseBtnArray.size()); So how can i refer to these buttons because they themseleves don't have a referance. Here is one way: `courseBtnArray.get(1).addActionListener(clickListener);`. This works, but the user does have the ability to add …

Member Avatar
Member Avatar
+0 forum 2

Hey Fellas, I created 10 JTextFields using and ArrayLists: `ArrayList<JTextField> textFArray = new ArrayList<>();` textFArray.add(new JTextField()); gbc.gridx = 1; for (int i = 0; i < 10; i++) { gbc.gridy++; add(textFArray.get(i), gbc); textFArray.add(new JTextField(i)); } What I need to do: I need to get the values of what ever the user puts into the JTextField(s) and total the inputs and assign them to a variable. This is what I have so far: double totalTemp; for(JTextField temps: textFArray){ //System.out.println(temps.getText()); totalTemp = Integer.parseInt(temps.getText()); } I know the code snippet above doesnt work properly. If you uncomment the the one line, it can …

Member Avatar
Member Avatar
+0 forum 1

Hey Everyone, I want to instantiate an ArrayList in java. I realize the method to doing this is: ArrayList<String> determiners = new ArrayList <String>(); determiners.add("A"); Where "A" is added to the arraylist once created. However, the problem I'm having is that the .add method doesn't work unless in a main method. What is the santax for making it work in a class without the main method. Thanks

Member Avatar
Member Avatar
+0 forum 8

Hey I'm trying to add pairs of numbers into an array by placing them into objects then putting the objects into the arrays but I seem to be having a problem with some part of my code. When I run the following example I just get the following back : [Example$Pair@1fc4bec, Example$Pair@dc8569, Example$Pair@1bab50a and so on...] can someone tell me why this is happening and how do I go about just printing the contents of the arraylist out correctly? import java.util.*; public class Example{ ArrayList<Pair> ar1 = new ArrayList<Pair>(); public static void main(String args[]){ Example example = new Example(); example.createArray(); …

Member Avatar
Member Avatar
+0 forum 10

I have the following code which is in a class called customerModel. How do I call this method to another method inside another class called customerController? I am abit new to this and have been trying for ages but have had no luck. Please help thank you. public class customerModel{ ....... ....... public ArrayList<Customer> search(Customer cust) { ArrayList<Customer> custs = new ArrayList<Customer>(); Connection connection = GaritsConnectivity.connect(); Tuple<ResultSet, Statement> trs = GaritsConnectivity.read("SELECT * FROM Customer WHERE Name=1", connection); ResultSet rs = trs.getFirst(); try { //takes a customer, returns it with the correct ID set while (rs.next()) { custs.add(createFromRs(rs)); } } catch …

Member Avatar
Member Avatar
+0 forum 5

Hey guys I'm having a bit of touble assigning the toString to a string from an index of an array list, any help would be appreciated. @Override public String indentedToString(int level) { String answer = " "; answer = super.indentedToString(level); answer += "Value " + this.list.toString() + "\n"; for(int i = 0; i < list.size(); i ++) { answer += list[i].indentedToString(level + 1); } return answer; } I keep getting an error in line 9 [array required, but java.util.ArrayList found] any help ? Thanks in advance

Member Avatar
Member Avatar
+0 forum 2

I Basically wanted to take an input and store it into a 2D Array called mat with a 3x3 size so i tried taking an input string, convert them into char and then sotring them in an array list and this is what i wrote so far. System.out.println("Enter Message"); Scanner Scanner1 = new Scanner(System.in); String plaintext = Scanner1.next(); int counter = 0; while(plaintext.length()>0){ // will get chars till the end of input length char text = plaintext.charAt(counter); counter++; ArrayList mylist = new ArrayList(); mylist.add(text); System.out.println(mylist); // chars of string } // How can i convert this ^^ list into A …

Member Avatar
Member Avatar
+0 forum 2

Hi, I am currently making an assignment for JAVA, but I get stuck at the following. I need to make a simulation of a shop where a customer puts objects in his "basket" and with that basket you go to the checkout counter. Now we have to make it possible that you can put objects that are created with the class article into an array list in the class basket with a method that is in the class person. So we have a class person, basket, article and counter. We already have a method in basket to add articles: public …

Member Avatar
Member Avatar
+0 forum 6

Hey guys i am in trouble about BST Tree exercise.. i need to create an array that can take number of elements user want and the user has to enter integers but the program need to get this number in one line ... Here is code that i already wrote ; #include<iostream> #include<string> using namespace std; int main(){ int size,snumb; cin>>size; string *myArray = new string[size]; for(int i=1;i<=size;i++){ getline (cin,myArray[i]); } cin>>snumb; system("pause"); }

Member Avatar
Member Avatar
+0 forum 2

Hi. I have a little problem with my code. I want to cast a complete arrayList to a different type, but java wont let me... Here is a compressed version of what is happening: [CODE] //The interface I use. public abstract interface Drawable{ //some methods } //A class that is supposed to be drawable public abstract class pObject implements Drawable{ //Methods } //A class that works magic on the objects public class engine{ ArrayList<pObject> obs = new...; //Method returning the pObjecs, that is drawable public ArrayList<pObject> getList(){ return obs; } } //The rendering work horse public class drawer{ arrayList<Drawable> draw …

Member Avatar
Member Avatar
+0 forum 9

import java.util.*; public class Elway { public static void main(String r[]) { ArrayList[] ls = new ArrayList[3]; for(int i=0; i<3; i++) { ls[i] = new ArrayList(); ls[i].add("a" + i); } Object o = ls; do3(ls); for(int i=0; i<3; i++) //insert code here } static Object do3(ArrayList[] a) { for(int i=0; i<3; i++) a[i].add("e"); return a; } } The code above compiles fine with: a. `System.out.println(((Object[])o)[i] + " ")` b. `System.out.println(((ArrayList[])o)[i] + " ")` but not with c. `System.out.println(o[i] + " ")` What is the reason? When we assigned ls to o, didn't Object o become an array?

Member Avatar
Member Avatar
+0 forum 4

Hello all. So I have a little problem with my school project. We are to create a snack machine with cookies and mints and interact with it using a GUI. We click the add Mints or Cookies button to add to the 'Snack Machine' and then click buy to purchase from the Snack Machine. A project.java file given to us(we MAY NOT change anything inside it) tests for a null list and if it exists it prints "Purchase fail". My problem is that the error box doesnt show up when I attempt to purchase without having added any Mints/Cookies, instead …

Member Avatar
Member Avatar
+0 forum 1

Let's say I have an array/arraylist(doesn't matter) with the following content: 2, 2, 2, 4, 5, 5, 8, 8, 8. How wold I go about counting the different values, in other words; how would I find out that there are 3 twos, one 4, 2 fives and 3 eights. How would like to get an attay(or arraylist for that matter) with the content: 3, 1, 2, 3. How would I go about doing that?

Member Avatar
Member Avatar
+0 forum 3

The End.