File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes if statement (using BlueJ) and equalsIgnoreCase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "if statement (using BlueJ) and equalsIgnoreCase" Watch "if statement (using BlueJ) and equalsIgnoreCase" New topic

if statement (using BlueJ) and equalsIgnoreCase

kel dobson

Joined: Dec 20, 2003
Posts: 5
I have trouble in BlueJ with anything other then a very simple test to an 'if' statement.
Can I compare a new input string with equalsIgnoreCase with a name recovered from an ArrayList object by using toString() and passing the 'name' variable back to the constructor of the first class to prevent two similar names being input?
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
Can you write down your program ?
1. "compare a new input string with equalsIgnoreCase with a name"
2. "recovered from an ArrayList object by using toString()"
??? arrayList.toString() -- WRONG
String name = (String)arrayList.get(i) -- OK
3. "and passing the 'name' variable back to the constructor"
4. "of the first class to prevent two similar names being input?"

My version:
ArrayList list = new ArrayList();
String str = inputString();
String normalizedStr = str.toLowerCase();
if( list.contains(normalizedStr) )
System.out.println("Already exists");
inputString() - function that ask user to input string somehow...
[ December 22, 2003: Message edited by: Igor Ko ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I dunno how you did that Igor
Kel, please attempt coding it yourself and posting the code here. We'll be pleased to help once we can understand what you are trying to do. Use the "code" button below the edit box so you can make the code keep its formatted layout.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
kel dobson

Joined: Dec 20, 2003
Posts: 5
Hi Guys
Problem is a java program in BlueJ, which needs to store names and ages in an arraylist for members of a "computer games club" for my college project. A second arraylist holds a list of computer games
I want to stop members "enrolling" using the same name - eg 'Fred and Fred = no' 'Fred and Freda = ok'
Classes: Member and Club. Member holds instances of members and Club is an arraylist for members
With help from others at JavaRanch I have got this side of the project running. Part of my problem (apart from being stupid!) is getting communication between two different object / classes, and to some extent
this seems compounded by BlueJ which doesn't always do what I think it should ??
I was trying to use similar syntax to a system.out.println call to return the 'anme' field from objects in the arraylist to compare with each new object in the constructor of Member.
I have been trying a method call to Club which I have called 'public void nameFromArrayList()' but the code is getting messy and I have commented out some lines I have tried just to keep it compiling and running. Anyway apologies for my code - it seems over long compared with the examples I read on these forum pages.
tia kel

[ December 23, 2003: Message edited by: kel dobson ]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
What's your question, exactly?
If it's still what you inquired about at the top of this thread, then sure you might be able to do something like that, and Igor has already posted one partial solution. There might be a simpler/easier-to-understand way to accomplish such a task.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: if statement (using BlueJ) and equalsIgnoreCase
Similar Threads
String Problem.
Test user input against an array
Beginning Debugging - how to make this work?
method help
String index out of range