Hey guys I need to display a table showing a list of products, such as product price unit apple 1.00 3 pear 2.00 4 can some one please get me started on this, thanks also i will need to add a method for displaying Total price such as product price unit total apple 1.00 3 3.00 pear 2.00 4 8.00 if ... |
hey guys, Just a quick question, ive delcared and initialised a list array to contain the numbers 1 - 100 as follows; String num = "1"; int n = 100; List number = new ArrayList(); for (int i = 0; i < n; i++) { number.add(i); } i think so far so good, now all i want to do is compare ... |
|
|
In the JavaDocs, it says Arrays.asList returns a List. But in my code when I call the add() method off what it returned, it says it is an unsupported method. And in my debugger when I look at the variable it says that it is of type "Arrays$ArrayList" Does anyone know which is correct? Is it an array, a List or ... |
|
Hi everyone, I need a very quick tutorial with array lists-I have used the API and searched through 3 books but just can't get it. I have the following code in a program: public void pickup(Passenger passenger) { passengers.add(passenger); destinations.add(passenger.getDestination()); } Both destinations and passengers are ArrayLists (or could be linked lists, doesnt matter)A passenger object and their destination is added ... |
|
Following code is based on code from K&B SCJP Study Guide p. 559. import java.util.*; public class ArrayToList { public static void main( String[] args) { String[] sa = { "one", "two", "three", "four", "five"}; List sList = Arrays.asList( sa); // make List from array System.out.println("List size : "+ sList.size()); System.out.println("List elem2: "+ sList.get(2)); sList.set( 3, "set"); // change list sa[1] ... |
Dear Sir, I have a Object array and i want to add data inside, rite now i am adding two list inside setToList (it is a araylist) subFileList2 (it is a araylist) Object[][] data = { {setToList, subFileList2} }; the problem is i want to add all element of List to the data array. for example Object[][] data = { {setToList.get(0), ... |
if you want to change a List into an Integer[] you can try the Collection.toArray(T[]) method. This uses generics so is java1.5 and later only. Have a look at the javadoc for this to understand its behaviour - it may not be exactly what you need (ie it does not give you an array of primitives). However, I'd probably approach this ... |
|
|
|
|
This is something that has long irritated me, but I've never been able to find a solution. If I have a List of apples and I want to turn it into an array of apples, I have to do this: List apples = getApples(); Apple[] applesAsArray = new Apple[apples.size()]; for ( int i = 0; i < apples.size(); i++ ) { ... |
Hi, I have an issue. Imagine a method which takes two parameters a list and an array, which contains indexes of elements to be removed from the list. I have come with a solution to the problem, i will paste the code here. This solution is working, if any of you see any problem with this one, kindly mention. If any ... |
I have a List List myList has [[UK, 1, 10.13.64.1, A, CACHE], [UK, 1, 10.13.64.2, B, CACHE], [UK, 1, 10.13.64.3, C, CACHE]] stored in it, I need to put this data in a Table. so for the row and column it will be A B C D E 1 UK, 1, 10.13.64.1, A, CACHE 2 UK, 1, 10.13.64.2, B, CACHE 3 ... |
|
I don't need to sort. I need to know how to move first item in the list to the bottom of the list. String inputString = "alpha|beta|gamma|delta"; String tokens[] = inputString.split("\\|"); int numTokens = tokens.length; for (int i = 0; i < numTokens; i++) { System.out.println("[" + i + "] " + tokens[i]); } Output from syst out print: [0] alpha ... |
private void deleteContact() { if (index >= 0) { JDialog.setDefaultLookAndFeelDecorated(false); int response = JOptionPane.showConfirmDialog(null, "Delete contact " + jtfName.getText() + "?", "Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { pb.deleteContact(index); dList.removeElementAt(index); try { fillList(); } catch (Exception e) { e.printStackTrace(); } } } else JOptionPane.showMessageDialog(null, "No contact to delete", "Delete", JOptionPane.ERROR_MESSAGE); } |
I convert an ArrayList String to array string. Please give me some tips if you have how to handle a better way to have array string instead of typing 45 times as below. ArrayList al = getIngestor(); Object ia[] = al.toArray(); Object [][] rowData = { { ia[0].toString(), ia[1].toString(), ia[2].toString(),ia[3].toString(),ia[4].toString()}, { ia[5].toString(), ia[6].toString(), ia[7].toString(),ia[8].toString(),ia[9].toString()}, { ia[10].toString(), ia[11].toString(), ia[12].toString(),ia[13].toString(),ia[14].toString()}, { ia[15].toString(), ia[16].toString(), ... |
partNo Description quantity i 123 Shampoo 24 224 Blue Biros 56 225 Red Biros 32 324 Cheese 15 369 Shower Gell 8 145 Green Olives 35 Hello, i am new to this forums and i have a problem with my project. I have to code an inventory control system for warehouse. This is the list of information i need to store ... |
System.out.println("Enter CAMPUSNAME REG-NUMBER UNIT1-UNIT2-UNIT3-...-UNIT8 the units MUST not exceed 8: ") String studentsInput = new Scanner(System.in).nextLine( ); String inputParts [ ] = studentsInput.split( " ") ; /*campus, regNumber units and unitCodes [ ] were declared as instance fields somewhere up there ^ /* campus = inputParts[ 0 ]; regNumber = inpuParts[ 1 ]; units = inputParts[ 2 ] ; |
HI everyone, I am working on an application to help students in our university register units(well don't mind units, something like subjects to be undertaken in a particular semester) on-line.Now I have everything working up to the point of registration so definitely it would be a good idea to tell the student of not only the successful unit registration but also ... |
I'm trying to write a program that allows a user to input an album title and a set number (10) of songs for that album. Then the album is saved in an array list. When the user is finished inputting, the program then prints out all of the songs inputed. This is my main class, CD. Java Code: public class CD ... |
At the moment im trying to create a programme that creates a list of rooms and i need to list the rooms. Also i think i need a static method to list all the rooms i have created outside of the class/constructor. Java Code: //the constructor sets the Building name and the number of arrays it holds (3 arrays) //from its ... |
import java.util.Scanner; import java.util.Arrays; public class array { public static void main(String [] args) { Scanner console = new Scanner(System.in); int arraysize; int value; System.out.print("Enter size of array: " ); arraysize = console.nextInt(); int[] array = new int[arraysize]; for(int x = 0 ; x < array.length; ++x) { System.out.print("Enter value #" + (x+1) + ": " ); array [x]= console.nextInt(); } ... |
import java.util.ArrayList; public class Club { private ArrayList members; /** * Constructor for objects of class Club */ public Club() { members = newArrayList members; } /** * Add a new member to the club's list of members. * @param member The member object to be added. */ public void join(Membership member) { } /** * @return The number of members ... |
Hello everybody! I am new to java and i have a problem. I need to create an arraylist from the coordinates the real and estimated values that I have read from a file.But i can't seem to do that! Can you help me please?? I woul really appreciate your help cause i m lost!!! |
Hi, I am trying to develop a servlet that parses Google Calendar XML data. Getting XML and parsing is OK, but when it comes to storing the data to Array, which is "Listgcalendar", a funny thing happens. In the code below, at "//HERE!!!" the data is to be stored in the array defined in the servlet. And at "//AGAIN HERE!!!", three ... |
Hi , I have a list A which can have maximum 13 elements depending on users input. I have an array B which has 15 elements now I have to do is B[2]=1st elemnt of list A if present B[3]=2 nd elemnt of list A if present B[4]= 3rd elemnt of list A if present . . . . Please help ... |
How do you want to access the data? With a Map, the key could be the host, and the value could be a list of ports. if you want the value to be heterogeneous (ie different types) make your own class to hold the variable bits and pieces and lists that you want to save for each host. |
|
Are you new to programming Java, or new to programming in general? Because arrays are not a new concept to Java...most all modern programming languages have arrays. If you want the basics on arrays, read the Sun tutorial on them: [http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html] An ArrayList is similar to an array, but is not of a fixed size. It can automatically grow as you ... |
|
|
|
Hello I am having a little difficulty with LinkedLists I have a LinkedList containing a number of arrays e.g. linked list ARRAY contains {array1,array2 ,array3...ect} I can read my data into the arrays and store my arrays in the LinkedList But how can I extract just one array from the linkedList based upon location (index) in the LinkedList Say for example ... |
If you can't show more code, then try to explain the problem in greater detail. As I have mentioned on another thread today: Please put as much effort into presenting your question as you would hope someone will put into answering it. I have questions about what your videobean does, how it stores your data, why you are creating a new ... |
Array Size cannot be dynamically assigned, else u need to use Vectors. Or u can try tis logic.. Create a string buffer put all the generated numbers in the string seperated by a dash. After ur generation of no.s ,use string tokenizer and get the individual strings and type cast them back to int(if you want) Message was edited by: AbiSS ... |
|
|
|
|
The basic GC strategy is called "Mark and Sweep". It follows references from active Threads to find all the objects that are reachable by the program, then it discards everything else. I visualise it like this: Imagine your program data as a set of cards (objects) connected together with wires (the references). Take a firm hold of the active Thread objects ... |
|
I agree with the two previous posters -- don't reinvent the XML parsing wheel. Besides JAXB, another schema-based solution is [XMLBeans|http://xmlbeans.apache.org/]. No one has mentioned the word "database" but you, so chill, bro. Finally, why do you say arrays are simpler than lists? Because of their limitations they are almost always harder to work with than lists. |
|
|
Hi all, I have a List which contains around 1000 elements. The structure can hold "" or string values - the pattern I would like to identify is where I have e.g. 30 "" elements then 50 elements with values and then again 20 "" elements. The code needs to extract the non "" elements in the list... I need to ... |
In the book "Effective Java" from Joshua Bloch on page 119 (Item 25) he states: "Generics by contrast, are implemented by erasure [JLS, 4.6]. This means that they enforce their type constraints only at compile time and discard (or erase) their element type information at runtime." What I do wonder now: If the type information is discarded at runtime then what ... |
Hi ardmore, this might work; I think ArrayList a=new ArrayList(); a.add(...); //adding all elements to arraylist ///.....................In arraylist you have all the elements now. TreeSet h=new TreeSet(); h.add(a); //adding all elements from arraylist to hashset h // In tree set all are sorted or Collection.sort(h) //might work if h is hashset a.clear; a=new ArrayList(); a.add(h); //Now w will get all the ... |
|
|
I'm writing a program which will store a massive arraylist to a text document. In this arraylist will be some objects and other arraylists. Is it possible to read the arraylists and objects, store them to another temporary arraylist, and use them again? (It's kind of like a save file I'm working on...) Any kind of hint would be fine if ... |
|
|
|
|
|
|
|
|
|
Hi all. I am trying to figure out the best way to do the following: I need to store serveral strings into a structure so that I can compare them against a string and see if the string is contained in the previously mentioned strings. I want to make the structure static, as it should not change, and I only need ... |
|
|
You got exactly what I got. And, it is exactly the problem! [] AnimalsI [OO-3.1] Dog [TgtObj-3.1] Barks [OO-3.2] Cat [TgtObj-3.2] Hacks up furball The above is produced by the System.out.println( ... ) before "each" of the Array (titleArray) is added to the List (recursiveTextArray). No problem! But, I want to write the List out in the static void main(String[] arg){ ... |
|
|
While were at it, I have a off topic elementary math question. Part of my assignment also requires me to calculate the volume and area of a octagonal polygon, equilateral triangle polygon, square polygon and pentagon polygon... Problem is, all we have is "edge length" - which is specified is edge means side and if so what side... and "height" to ... |