I have been given a task to do, which is to create a memberList and populate it with data. The constructor has been created with me, but I am required to add code to display the memberList. I am also required to creates a method to display members.This is the method I created:
/**
* Populates the list of members.
* Displays the membership numbers and names of library members in ascending membership number order.
* The first member is selected by default.
*/
public void displayMembers()
{
initComponents();
library = new LibraryCoord();
Collection<Member> Member = library.getMembers();
memberList.setListData(Member);
memberList.setSelectedIndex(0);
[code]....
The code below TO DO is mine.What is meant to happen when I run the project is for a GUI form list to show the members of memberList. However, it does not.
I have some class called sorted to sort the linked list through the nodes of the list. and other class to test this ability, i made object of the sort class called "list1" and insert the values to the linked list.
If i make other object called "list2" and want to merge those two lists by using method merge in sort class. And wrote code of
list1.merge(list2);
How can the merge method in sort class know the values of list1 that called it as this object is created in other class.
public void add(int d){ listNode l = new listNode (d, null); l.next = first; first= l; } public list Sum2List (list l1, list l2){ //variables int sum;
[Code] .....
But I have a problem in my first listNode where it ll be pointing to null, thus in the sum2List method the program checks the while condition into false and doesn't go through the loop.
Trying to make a swing box where you can type in string data to the text field and a button. I want the string data to be added to a list everytime you press the addbutton.
I'm trying to get a primefaces data list working and not sure I'm doing this correctly, having a problem with getting this view to display. Here is my xhtml .
Is this the proper way to add to a generic list? My code works just fine, but I got this feeling that there might be some kind of flaw in it or something. Is this pretty much the basic way to add any type of data to a generic list?
import java.util.LinkedList; public class ListOfGeneric<E> { private LinkedList<E> myList;
TL,DR: observe the nodes just below, that is the data each node in the link list contains. How do I iterate through the entire list to reach the last element (H), so I can add an element right after it?
So I have 4 nodes doubly linked with two dummy nodes for head and tail:
Ok, so since the list only contains 8 elements that are not null, its size is actually 8 correct? So now lets say I have an add method that has
add(E item) and inserts the item at the end of the list. So I can get to the last node with tail.previous(), but then how do I iterate to the end so I can add the item after the last item in the list (H). I guess I don't know how you only access one nodes data when that data is an array with empty spaces.
Here is the entire Node code:
Also, I can't just iterate through the whole thing because I am not supposed to. I am supposed to just find the right node and iterate through that only.how to maneuver around a linked list containing nodes where each node contains an array.
/** * Node class that makes up a DoublingList. Feel free to add methods / * constructors / variables you might find useful in here. */ public class Node<E> {
/** * The node that comes after this one in the list
Is it possible to get the list/ values in html/jsp from servlet?
I have a table inside an html/jsp page and when the user clicks a button I need to refresh the whole page with some additional text message.
Currently what I am doing is that I am using a java bean for the jsp page that contains a list of values inside the table then store it in session but I think there is a better way without storing it in session.
I tried using request.getParameter() but it only returns string.
i am newbie to servlet and m working on a project like online shopping. I have list of data items in my database and i am able to fetch and display the data from database but i want to know that how can i store these data items in ServletContext so that i can use use it frequently in other pages.
I just trying to find the most efficient way to do this. I read in a csv file into a linked list and then I split the linked list into sections based on category for each element. Of course I used an array to split each element of the list. However I can do the sequential search by either ID and Name by using hashmap and making the key = name + ID and then doing key.contains(charSequence);. However I feel like this is inefficient and I would like to use the linked list instead of a hashmap which could be done by splitting the user input and used for method overloading by passing an int in one and a string in another. I feel like this approach is a little more redundant and maybe their is a better approach for searching for id and name. Below is an example of the elements in a linked list.
note: their are more elements than this.
element 1
name: George address: 4410 something dr. phone number: 978-888-6666 id: 43
element 2
name: Karla address: 339 something dr. phone number: 334-338-6556 id: 23
I'am new to java, this question may have been asked earlier but I'm not getting the exact answer.I want to add data from database into at and display it through jsp. But empty or null values is shown i.e no data is being displayed and when I execute the same sql query which is used in code in sql server then required output is displayed. My java code is:
Java Code:
public List < Alarm_Bean > get_Count(String system_Name) { if (system_Name.equals("MPS")) { try { con = getConnection(); stmt = con.createStatement();
AddItemToFront(Item p) : This method will create a new Node with the Item object as its data value and then add the newly created node to the front of the linked list.
DisplayItems(): This method will traverse the linked list from first node to last node and print data value ( i.e., id, name, type and price of the Item object) of each node.
RemoveItemAtPosition(int n): This method will remove the node at position n in the linked list. Assume that the first node of the linked list has a position number of 1 and the second node has a position number of 2 and so on.
This is my Code
AddItemToFront public void AddItemtoFront(Item p) { Node newNode = new Node(p); newNode.setLink(head); head = newNode;
[Code] ....
I don't know what am I suppose to do inside the remove method
This is the method public void populateMatrices(int [][]mat1, int [][]mat2). I know how to do it for one matrix, but what do we do for the additional matrix? Here is the code I have so far.
for (int row =0; row<mat1.length;row++){ for (int column = 0; column<mat1[row].length;column++){ mat1[row][column]=1 + (int)(Math.random()*5);
I have a method that accepts JSONArray as parameter and returns the values of it as ArrayList Object. My question which of these ways is appropriate in populating the ArrayList object this method populates the arraylist upon creation of object (I don't know what the right term to use, but as netbeans IDE suggest, JSONArray object should be final since it was used in inner class.).
private List<String> getStringList(final JSONArray jsonArr) { return new ArrayList<String>() { { try { for (int i = 0; i < jsonArr.length(); i++) { add(jsonArr.getString(i)); } } catch (JSONException ex) { ex.printStackTrace(); } } }; }
this second method is the usual way of populating collection
private List<String> getStringList(JSONArray jsonArr) { List<String> strList = new ArrayList<String>(); try { for (int i = 0; i < jsonArr.length(); i++) { strList.add(jsonArr.getString(i)); } } catch (JSONException ex) { ex.printStackTrace(); } }
What are the advantages and disadvantages between the two? like which is faster? or which consumed larger memory?
I am trying to populate a Jlist for information stored on a database. The database contains football club names, but instead of being populated with their names it just has a hexadecimal reference ( Club@183357c4 ) for each club object.
Write a Java function Sum2List that takes two lists L1 and L2 of the same size and returns list L that contains the sum of data inside the corresponding nodes of lists L1 and L2.
I'm not sure this is right... Is there a way to automate this process? What if we have arrays like int[][][] Terms? This is terrible... Is there a software tool for this?
I am having a hard time trying to wrap my head around trying to get a couple of columns in a datatable populated with values from a @OneToMany collection. The concept is simple but my brain refuses to grasp it!! I will try to make this brief...
I have several forms built with primefaces 3.5 using NetBeans 8 IDE on a JBoss EAP 6.21 server, and JPA 2.1 annotations. Data is extracted from an Oracle 11 database, which consists of several lookup tables, as well as a primary table and secondary table. Using the EntityManager createQuery method I query the database, which of course returns a resultset. The query grabs all records from the primary, as well as values from 2 specific columns of the secondary database, based on search criteria entered by the user on a primefaces search form. The returned results are then iterated through, this is where I am trying to get the values from the secondary table to populate specific fields in the datatable.Here is the applicable code from the list.xhtml form containing the datatable:
As odd as the code may look (and I will completely understand anyone cringing as to some of the coding methods I use), specifically with the ui:repeat tags nested inside the datatable tag of the list.xhtml form, I strangely do see the values from the secondary table showing up in the form showing the results in a datatable. However, when the user clicks on a specific record in the returned resultset listed in the datatable, another form is opened and populated with the values from the datatable, but the 2 fields on that form that should be populated with the 2 values I referred to before from the secondary table (i.e. policy1Num and totalPayoutAmt) do not have the values in them.
This is partly because I have those 2 fields in the editable form pointing to the managed bean of the secondary table (code from that bean not shown here), rather than the same "polNum. policy1 Num" and "totPayout.totalPayoutAmt" var I am using in the list.xhtml form. How those values are being successfully returned into the datatable of the list.xhtml form - I happened to "stumble" across the use of the "polNum" and "totPayout" vars with the "policy Payment Collection" list. I do not know how to do the same thing for those 2 fields in the editable form.how a datatable gets populated, specifically with values in a @OneToMany collection,
I am trying out solving the question but i am stuck.The problem is to write a method that print data of single linked list backward using stack.The question is as follow
public class Stack{ public boolean isEmpty(){}; public void push(int n){}; public int peek(){}; public int pop(){}; }
I have created Person.java with the following attributes:
private String firstName; private String lastName; private int age;
My main method parses the XML, loops through each person, and gets the attributes for each.
I need to create instances of my Person class. I could write something like this:
Person person = new Person(); for (int i = 0; i < attributes.getLength; i++) { if (attribute.getName(i) = "firstname") { person.firstName = attribute.getValue(i);} if (attribute.getName(i) = "lastname") { person.lastName = attribute.getValue(i); } if (attribute.getName(i) = "age") { person.age = attribute.getValue(i); } }
Since my actual XML has quite a few attributes, I would rather do something like this:
Person person = new Person(); for (int i = 0; i < attributes.getLength(); i++) { person[attribute.getName(i)] = attribute.getValue(i); }
import java.io.*; import java.util.Scanner; public class asciiFile { int height; int width; Scanner input; char[][] poop; public asciiFile(File f) throws FileNotFoundException{ //constructor
[code]...
The constructor is supposed to take an ASCII file, take the numbers in the file, and populate a 2D array with the numbers in the file.
For some reason, the for loop I use to populate the array works outside of the constructor. When I put it in one of the methods, it runs normally. However, when I keep it in the constructor, I get the following error:
Exception in thread "main" java.lang.NullPointerException
My code runs and populates an arraylist. However my break statement, while stopping the loop ends up being added to the arraylist. And I'm not sure how to fix this error.
public static void main(String args[]) throws Exception { // declaring variables String input = ""; // creating array list ArrayList<String> nameList = new ArrayList<String>();