I have to create a method which has an ArrayList; I need to remove even numbers from this ArrayList. I have written code for that but there is a logical error which I couldn't identify.
Here is my code:
static void sortList(){
List <Integer> number=new ArrayList <Integer>();
number.add(11);
number.add(45);
number.add(12);...
Hey everyone,
I am writing a program that will query an MS access database, return the query as a result set, and then I want to ultimately convert that result set into a String array, so that I can pass it into the constructor of a Swing JComboBox - so the ComboBox will list the items returned by the query.
I have been able to store t...
Taken from Apache TreeList doc:
The following relative performance statistics are indicative of this class:
get add insert iterate remove
TreeList 3 5 1 2 1
ArrayList 1 1 40 1 40
LinkedList 5800 1 350 2 325
It goes on to say, "LinkedList is rarel...
Hey guys this is a followup to my previous question. I now have a text file which is formatted like this:
100 200
123
124 123 145
What I want to do is get these values into a two dimensional ragged array in Java.
What I have so far is this:
public String[][] readFile(String fileName) throws FileNotFoundException, IOException {
...
Hi
I have the following problem:
I have a Web Service returning an ArrayList< CommunicationMedia > where CommunicationMedia is a superclass of many other classes and the List contains objects of these inheriting classes - the problem is, that wdsl generated does not contain any other declarations than CommunicationMedia itself - how do...
I have an ArrayList and i am trying to display it in a table
.....
ArrayList rows = ....
.....
<table cellspacing="1" cellpadding="4" border="3">
<tr>
<TH>
Heading1
</TH>
<TH>
Heading2
</TH>
<TH>
Heading3
...
I have a sorted map and want to reference its ordered objects by their index position. Is this possible? How would I convert a sorted map to an array list while maintaining the ordering, so I can retrieve an object by its index (order). Is this the only way to do it?
Ideally I could have this structure, and would know the index of an ob...
When I programin C#, there are times I need a strongly typed collection:
I often create a class that inherits from the ArrayList:
using System.Collections;
public class Emails: ArrayList
{
public new Email this[int i]
{
get
{
return (Email)base[i];
}
set
{
base[i] = value;
}
}
}
I r...
I have a big 2-dimensional array A, and also a flat array B of two elements. How can I quickly access element from the A array using numbers (coordinates) in B? The only thing I can do now is:
A[B[0],B[1]]
But the path to these actual arrays through the names of members of my class is too long and dirty, and the actual array names are...
Im working on a project for homework where I have an Arraylist containing objects of 5 strings. I know how to select items of the array list (using an index value) but not how to access the objects strings. Any help would be great (I'm not trying to cheat but its getting frustrating that I cant't sort it out. I hope this snippets make it...
I am using VS2008, and ASP.NET 3.5 C#
I have an array list that is populated using a textBox & button for input of numbers.
After clicking the button, I need to display the highest number in the arraylist.
So far I know I need a loop to compare the the items within the arraylist.
using System;
using System.Collections.Generic;...
Previously I would always have thought a Vector was good to use for non-descript objects when length was unknown. As far as I was aware I thought it was thread-safe too
What would change that it shouldn't be used anymore, and what is the alternative?
...
How do you go about comparing two generic classes?
class Entry<K,V>
{
protected K key;
protected V value;
public K getKey() { return key; }
public V getValue() { return value; }
public static Comparator KeyComparator = new Comparator()
{
public int compare(Object o1, Object o2)
{
int key1 = ( (Entry) o1 ).getKey();
int...
I am working on learning java a little, and i found this question in a java text book on Google books, I have been working on it for a while, and for some reason these seems like it should be simple. Anyone bored and would like to show me what this is suppose to look like in Java code??
(Using ArrayList) Write a program that creates an ...
This is an undo feature button on a calculator that I am writing. undo is the button Status is a class that holds my status. listOfStates is an ArrayList of Status. displayBox is a object of JTextFeild. What I do not under stand is that when I display previousState in the text box I get something like: Status@11dc088. I know I am missin...
I have an ArrayList and wish to be able to call an index and use the returned string for a method call.
e.g.
stringList.get(2)();
Is there any way I could go about this?
...
I know that I am missing something simple here. I have got this homework all done except for moving through my ArrayList. This is a undo feature of a calculator that I need to pull and remove a object from an ArrayList. Here is the method:
public void actionPerformed(ActionEvent e)
{
Status state;
state = new Sta...
Hi, I'm trying to delete an item from an array list by selecting it from a JList and clicking "Delete"......
The code i have so far is
buttondeleteContact.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (contactList.getSelectedIndex() != -1) {
people.removeElementAt(contactLis...
Ok so I have a been making an addressbook application and have pretty much finished all the key features but I am looking to implement a sort feature in the program.
I want to sort an Arraylist which is of a type called Contact (contactArray) which is a separate class which contains four fields; name, home number, mobile number and addr...
I need some help. I want to create a for loop that creates n number of objects of a class, and then adds them into an arraylist. Something like this:
//Player is a custom class
ArrayList<Player> numberofPlayersArray;
numberofPlayersArray = new ArrayList<Player>();
//n is a variable for the number of Player class objects that I want to...