I have been working on this small problem for hours and cant seem to find problem, bassically it is not recognising a word when i compare user entered word to a word in the array list. Here is code:   birdToRemove = JOptionPane.showInputDialog("Type bird to remove, or cancel  to continue");     while(increment &lt;= amountBirds)     {          if(birdToRemove == birdArray[increment])         {             found = true;             birdArray[increment] = null;              JOptionPane.showMessageDialog(null, "Deleted");             deleteEntry();         }         if(birdArray[increment] != birdToRemove)         {             increment = increment + 1;         }     }      if(found == false)     {         JOptionPane.showMessageDialog(null, "Error, bird not found", "Error", JOptionPane.ERROR_MESSAGE);     }   Everytime it will say Error bird not found Kind regards Jordan
93
I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.  Is == bad? When should it and should it not be used? What's the difference?
108306
I'm trying to figure out what a Java applet's class file is doing under the hood. Opening it up with Notepad or Textpad just shows a bunch of gobbledy-gook.  Is there any way to wrangle it back into a somewhat-readable format so I can try to figure out what it's doing?   Environment == Windows w/ VS 2008 installed.
69342
I'm using this code to let the user enter in names while the program stores them in an array until they enter an empty string (they must press enter after each name):  people = [] info = 'a' # must fill variable with something, otherwise loop won't execute  while not info.empty?     info = gets.chomp     people += [Person.new(info)] if not info.empty? end   This code would look much nicer in a do ... while loop:  people = []  do     info = gets.chomp     people += [Person.new(info)] if not info.empty? while not info.empty?   In this code I don't have to assign info to some random string.  Unfortunately this type of loop doesn't seem to exist in Ruby. Can anybody suggest a better way of doing this?
40009
I have the following code that shows either a bug or a misunderstanding on my part.  I sent the same list, but modified over an ObjectOutputStream.  Once as [0] and other as [1].  But when I read it, I get [0] twice.  I think this is caused by the fact that I am sending over the same object and ObjectOutputStream must be caching them somehow.  Is this work as it should, or should I file a bug?   import java.io.*; import java.net.*; import java.util.*;  public class OOS {      public static void main(String[] args) throws Exception {         Thread t1 = new Thread(new Runnable() {             public void run() {                 try {                     ServerSocket ss = new ServerSocket(12344);                     Socket s= ss.accept();                      ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());                     List same = new ArrayList();                     same.add(0);                     oos.writeObject(same);                     same.clear();                     same.add(1);                     oos.writeObject(same);                  } catch(Exception e) {                     e.printStackTrace();                 }             }         });         t1.start();          Socket s = new Socket("localhost", 12344);         ObjectInputStream ois = new ObjectInputStream(s.getInputStream());          // outputs [0] as expected         System.out.println(ois.readObject());          // outputs [0], but expected [1]         System.out.println(ois.readObject());         System.exit(0);     } }
2156
In Java is there a way to check the condition:  "Does this single character appear at all in string x"  without using a loop?
8442
I have a file (called "number.txt") which I want to read to an array in Java. How exactly do I go ahead and do this? It is a straight-forward "1-dimensional" file, containing 100 numbers.  The problem is that I get an exception every time. Apparently it can't find it (I am sure its spelled correctly). When looking through code examples, it doesn't specify the file's entire file path, only the name of the file itself. How would I go about doing that if its necessary?  Also, when reading the file, will the array automatically contain all the lines of the file, or will I have to make a loop which which copies every line to corresponding subscript i?  I've heard of BufferedReader class, what it's purpose, and how does it corelate to reading input?
13332
I am trying to use a  as input and then creating a query with it - so I need a .    I was surprised to find that it couldn't do the conversion implicitly or explicitly - but I don't even know how I would do this, as the Java API is still fairly new to me.
92456
Alright, I have been doing the following (variable names have been changed):   FileInputStream fis = null; try {     fis = new FileInputStream(file);      ... process ...  } catch (IOException e) {     ... handle error ... } finally {     if (fis != null)         fis.close(); }    Recently, I started using FindBugs, which suggests that I am not properly closing streams.  I decide to see if there's anything that can be done with a finally{} block, and then I see, oh yeah, close() can throw IOException.  What are people supposed to do here?  The Java libraries throw too many checked exceptions.
92088
public class WrapperTest {      public static void main(String[] args) {          Integer i = 100;         Integer j = 100;          if(i == j)             System.out.println("same");         else             System.out.println("not same");     }     }   The above code gives the output of same when run, however if we change the value of i and j to 1000 the output changes to not same. As I'm preparing for SCJP, need to get the concept behind this clear. Can someone explain this behavior.Thanks.
42562
How could I go about detecting (returning true/false) whether an ArrayList contains more than one of the same element in Java?  Many thanks, Terry  Edit Forgot to mention that I am not looking to compare "Blocks" with each other but their integer values. Each "block" has an int and this is what makes them different. I find the int of a particular Block by calling a method named "getNum" (e.g. table1[0][2].getNum();
26480
I've been trying to find a way to filter a line that has the word "lemon" and "rice" in it. I know how to find "lemon"  or "rice"  but not the two of them. They don't need to be next to the other, just one the same line of text.
79687
This is a wild one: can anyone write a code that converts a number into the corresponding word? e.g.:  4 -&gt; 'four' 31 -&gt; 'thirty-one'   and so on. Obviously, it is not enough to build an array in which you can store the numbers and the word associated with it and then just print instead of the number the stored word. What complicates matters more, are numbers like 11 ('eleven'). I intend to use it for numbering equations. So, anybody up to it?
21175
Is there a way to determine if the loop is iterating for the last time. My code looks something like this:  int[] array = {1, 2, 3...}; StringBuilder builder = new StringBuilder();  for(int i : array) {     builder.append("" + i);     if(!lastiteration)         builder.append(","); }   Now the thing is I don't want to append the comma in the last iteration. Now is there a way to determine if it is the last iteration or am I stuck with the for loop or using an external counter to keep track.
18413
that I posted on Meta.Programmers was rather broken, with a block quote replaced by apparently random letters and numbers. Aarthi fixed it with a non-breaking space, but I don't understand what went wrong.  When I opened the post for editing, the displayed text was what I intended to go there. It only happens when the post is viewed in the reading mode. The preview also displayed the text correctly.
80428
I have a class like this:  public class myClass {   public List&lt;myOtherClass&gt; anewlist = new List&lt;myOtherClass&gt;;    public void addToList(myOtherClass tmp)   {     anewList.Add(tmp);   }  }   So I call "addToList" a hundred times, each adding a unique item to the list.  I've tested my items to show that before I run the "addToList" method, they are unique.  I even put a line in to test "tmp" to make sure it was what I was expecting.  However, when I do this (lets say myClass object is called tmpClass):  int i = tmpClass.anewList.Count(); for (int j = 0; j&lt;i; j++) {    //write out each member of the list based on index j... }   I get the same exact item, and it's the last one that was written into my list.  It's as if when I add, I'm overwriting the entire list with the last item I've added.    Help?  This makes no sense. I've also tried List.Insert, where I'm always inserting at the end or at index 0.  Still no dice.  Yes, I'm doubly source my indexing is correct and when I do my test I'm indexing through each of the elements.  :)  UPDATE: Okay, I tried this and still had the same problem:  foreach(myOtherClass tmpC in tmpClass.anewList) {         Console.WriteLine(tmpC.theStringInMyClass.ToString()); }   and still for each of the 100 items, I got the same string output... I'm sure I'm doing something completely stupid, but I don't know what yet. I'm still 100% sure that the right string is getting passed in to begin with.  -Adeena    Okay, I tried this and still had the same problem:  foreach(myOtherClass tmpC in tmpClass.anewList) {     Console.WriteLine(tmpC.theStringInMyClass.ToString()); }   and still for each of the 100 items, I got the same string output...  I'm sure I'm doing something completely stupid, but I don't know what yet. I'm still 100% sure that the right string is getting passed in to begin with.  -Adeena
47989
Okay, we know that the following two lines are equivalent -    (0 == i) (i == 0)   Also, the first method was encouraged in the past because that would have allowed the compiler to give an error message if you accidentally used '=' instead of '=='.  My question is - in today's generation of pretty slick IDE's and intelligent compilers, do you still recommend the first method?    In particular, this question popped into my mind when I saw the following code -   if(DialogResult.OK == MessageBox.Show("Message")) ...    In my opinion, I would never recommend the above. Any second opinions?
80089
I have seen a solution that I don't get to work - I need to change data type from string to integer and I did what is shown i the image below Can someone point out what I do wrong?