PeachParts Mercedes-Benz Forum

PeachParts Mercedes-Benz Forum (http://www.peachparts.com/shopforum/)
-   Off-Topic Discussion (http://www.peachparts.com/shopforum/off-topic-discussion/)
-   -   Anyone know Java/Object Oriented? (http://www.peachparts.com/shopforum/off-topic-discussion/293578-anyone-know-java-object-oriented.html)

TheDon 02-05-2011 09:49 AM

Anyone know Java/Object Oriented?
 
I'm stuck on a simple program that requires me to check two words if they are anagrams.

I know C but java..just starting out. I can read in and print to a file, no problem, do loops, etc. But I cannot break this string "FOO BAR" or "FOO OOF" into two so I can then check them.

help?

Matt L 02-05-2011 10:11 AM

Not much about OO in your question. I assume that you're working with java.lang.String objects. What methods are you to use, or are you to look them up and decide for yourself?

TheDon 02-05-2011 10:16 AM

methods?

no idea.. I have an idea but I cannot figure out how to code it. I think when I get that one string split into to I can call compareTo() and that will give a boolean value if they are the same or not

Matt L 02-05-2011 10:21 AM

Functions in java all belong to some class, and are called methods.

You haven't defined the problem. Are you trying to split the string on spaces? If so, you can search the string for the spaces and extract substrings. Or you can use a regular expression.

Matt L 02-05-2011 10:25 AM

Here's an API reference: http://download.oracle.com/javase/6/docs/api/.

java.lang.string is described here: http://download.oracle.com/javase/6/docs/api/java/lang/String.html

TheDon 02-05-2011 12:09 PM

I looked up on gotapi and then a friend nudged me in the correct direction

I was using FIN.nextLine(); when I should have been using FIN.next();

that issue is solved, now to sort and compare

thanks!

MercFan 02-05-2011 09:21 PM

Quote:

But I cannot break this string "FOO BAR" or "FOO OOF" into two so I can then check them.
I'm a little unclear on your objectives: are you saying you need to break a string into individual words?! If so, you can use StringTokenizer class:
http://www.devdaily.com/java/edu/pj/pj010006

You can do very advanced String manipulations with RegEx (Regular Expressions). Let us know if you need more direction.

James

TheDon 02-05-2011 10:40 PM

Quote:

Originally Posted by MercFan (Post 2655452)
I'm a little unclear on your objectives: are you saying you need to break a string into individual words?! If so, you can use StringTokenizer class:
http://www.devdaily.com/java/edu/pj/pj010006

You can do very advanced String manipulations with RegEx (Regular Expressions). Let us know if you need more direction.

James

I fixed it.. I needed to use .next() instead of .nextLine()

MercFan 02-07-2011 04:14 PM

Quote:

Originally Posted by TheDon (Post 2655115)
that issue is solved, now to sort and compare...

Be careful with comparing objects such as two Strings in Java as they are objects so obj1=obj2 does not yield predicatable results you need to use .equals() method, so it should be obj1.equals(obj2).

Hope it helps -
James

TheDon 02-07-2011 04:55 PM

U have an idea for my compare. Hoping it works


All times are GMT -4. The time now is 07:19 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0
Copyright 2024 Pelican Parts, LLC - Posts may be archived for display on the Peach Parts or Pelican Parts Website