Results 1 to 5 of 5
- 09-27-2008, 02:43 AM #1
Member
- Join Date
- Aug 2008
- Posts
- 4
- Rep Power
- 0
Passing a Vector object to a function
Hi:
I am working on a program that involves a string Vector object. I have to re-write the selection sort procedure using the vector object (instead of an array), and then re-write the binary search procedure also using the vector object. I already have the code written for an array for both procedures, but I'm just not sure how to pass the Vector object to my sort and search functions so that I can re-work the functions for the Vector. I've looked through multiple Java books I have, but none of them are helping, so I thought I'd post my problem here.
Any help would be greatly appreciated. If you need more info from me, just let me know and I'll post it.
Thanks in advance
-
Given the information you've provided, your guess is as good as ours. You may wish to provide more details, and in fact repost the question as if we can't read your mind or magically see your code.
- 09-27-2008, 02:58 AM #3
Member
- Join Date
- Aug 2008
- Posts
- 4
- Rep Power
- 0
Sorry I'm not the best explainer. Here's the code I have so far:
I commented out the two functions down at the bottom, and the lines commented out in MAIN are operations I can't do yet because I haven't written the sort and search functions yet.Java Code:import java.util.*; public class VectorOperations { static Scanner console = new Scanner(System.in); public static void main(String[] args) { Vector<String> stringList = new Vector<String>(); int ans; String target; int index; do { System.out.println("Enter a string to be added: "); stringList.addElement(console.next()); System.out.println("Would you like to enter another string?\n [ Enter (1) for YES and (2) for NO ]"); ans = console.nextInt(); } while (ans == 1); // selectionSort(stringlist); // System.out.println(stringList); System.out.println("Enter the item you would like to search for: "); target = console.next(); // index = binarySearch(stringList, target); // System.out.println("The string " + target + " was found at position: " + index); } // public void selectionSort() // { // } // public int binarySearch() // { // } }
So I just wanted to know if anyone knows a snytax for passing a Vector object to a function because I'm not familiar at all with Vectors, I've been using arrays for most of my programming life.
-
You declare a Vector parameter the same way that you pass any parameter: class name followed by a parameter variable:
Java Code:public void myFoo(Vector<String> stringVector) { //.... }
- 09-27-2008, 03:18 AM #5
Member
- Join Date
- Aug 2008
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Operator < cannot be applied to java.lang.Object, Object
By Albert in forum Advanced JavaReplies: 2Last Post: 11-26-2010, 02:12 AM -
Search a object in a vector
By TalhaS in forum New To JavaReplies: 2Last Post: 04-30-2008, 02:05 PM -
Problems passing a scan object to a method
By xkross in forum New To JavaReplies: 4Last Post: 04-16-2008, 03:56 PM -
URGENT: Sorting a vector of object by an element
By doobybug in forum New To JavaReplies: 1Last Post: 03-12-2008, 06:37 PM -
Passing a new object to a constructor please clarifiy the concept for me please.
By stefan24 in forum New To JavaReplies: 2Last Post: 07-09-2007, 05:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks