Parts Catalog Accessories Catalog How To Articles Tech Forums
Call Pelican Parts at 888-280-7799
Shopping Cart Cart | Project List | Order Status | Help



Go Back   PeachParts Mercedes-Benz Forum > General Discussions > Off-Topic Discussion

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 02-05-2011, 09:49 AM
TheDon's Avatar
Ghost of Diesels Past
 
Join Date: Oct 2005
Posts: 13,285
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?

Reply With Quote
  #2  
Old 02-05-2011, 10:11 AM
Registered User
 
Join Date: Oct 2005
Posts: 4,263
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?
Reply With Quote
  #3  
Old 02-05-2011, 10:16 AM
TheDon's Avatar
Ghost of Diesels Past
 
Join Date: Oct 2005
Posts: 13,285
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
Reply With Quote
  #4  
Old 02-05-2011, 10:21 AM
Registered User
 
Join Date: Oct 2005
Posts: 4,263
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.
Reply With Quote
  #5  
Old 02-05-2011, 10:25 AM
Registered User
 
Join Date: Oct 2005
Posts: 4,263
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
Reply With Quote
  #6  
Old 02-05-2011, 12:09 PM
TheDon's Avatar
Ghost of Diesels Past
 
Join Date: Oct 2005
Posts: 13,285
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!
Reply With Quote
  #7  
Old 02-05-2011, 09:21 PM
MercFan's Avatar
Registered User
 
Join Date: Nov 2004
Location: Denver, CO
Posts: 994
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
__________________
1987 Mercedes 300SDL; SOLD
1985 Mercedes 300D; SOLD
2006 Honda Pilot - wife's ride; 122K;
1995 Toyota Land Cruiser - 3X locked; 182K
Reply With Quote
  #8  
Old 02-05-2011, 10:40 PM
TheDon's Avatar
Ghost of Diesels Past
 
Join Date: Oct 2005
Posts: 13,285
Quote:
Originally Posted by MercFan View Post
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()
Reply With Quote
  #9  
Old 02-07-2011, 04:14 PM
MercFan's Avatar
Registered User
 
Join Date: Nov 2004
Location: Denver, CO
Posts: 994
Quote:
Originally Posted by TheDon View Post
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
__________________
1987 Mercedes 300SDL; SOLD
1985 Mercedes 300D; SOLD
2006 Honda Pilot - wife's ride; 122K;
1995 Toyota Land Cruiser - 3X locked; 182K

Last edited by MercFan; 02-07-2011 at 05:04 PM.
Reply With Quote
  #10  
Old 02-07-2011, 04:55 PM
TheDon's Avatar
Ghost of Diesels Past
 
Join Date: Oct 2005
Posts: 13,285
U have an idea for my compare. Hoping it works

Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:09 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, 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 -    DMCA Registered Agent Contact Page