Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-24-2007, 07:38 PM
Member
 
Join Date: Jul 2007
Posts: 11
fegiflu is on a distinguished road
Help with removing somthing once inputed.
This is my code, but i want to add a Remove function, so once you enter in a number, you can remove it from the Fill list.
the ; is suppose to be ;; and )
Quote:

public class SimpleSearchableList {

private static String[] List = new String[25];
private static int Size; unavailable


public static void main(String[] args)
{
String Cmd;

for(; {
Menu();
System.out.print("Command: ");
Cmd = SimpleIO.inputString();

if(Cmd.equals("Quit"))
break;
else if(Cmd.equals("Fill"))
FillList();
else if(Cmd.equals("Remove"))
RemoveList();
else if(Cmd.equals("Search"))
SearchList();
else if(Cmd.equals("Show"))
ShowList();
}

}



public static void Menu()
{
System.out.println("Choices....................... ...........");
System.out.println("\tFill the list");
System.out.println("\tRemove List");
System.out.println("\tShow the list");
System.out.println("\tSearch the list");
System.out.println("\tQuit");
System.out.println(".............................. ...........");
}


public static void FillList()
{
int Count;

for(Count = 0 ; Count < List.length ; Count++)
{
System.out.print("Enter: ");
List[Count] = SimpleIO.inputString();
if(List[Count].equals("Stop"))
break;
}

Size = Count;
}






public static void SearchList()
{
String KeyValue;
boolean NotFoundFlag;
int K;

System.out.println("Enter Names Below, Stop To Quit");

while(true)
{
System.out.print("Enter: ");
KeyValue = SimpleIO.inputString();
if(KeyValue.equals("Stop"))
break;

NotFoundFlag = true;

for(K = 0 ; K < Size ; K++)
if(List[K].equals(KeyValue)) {
NotFoundFlag = false;
System.out.println(List[K] + " found");
}

if(NotFoundFlag)
System.out.println(KeyValue + " Not Found");
}
}


public static void ShowList()
{
int K;

for(K = 0 ; K < Size ; K++)
System.out.println("List[" + K + "] = " + List[K]);
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2007, 07:44 PM
Member
 
Join Date: Jul 2007
Posts: 8
momo97 is on a distinguished road
One thing you can do is to make a new array without the value that you enter for removal, and then show the new array.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-24-2007, 10:01 PM
Member
 
Join Date: Jul 2007
Posts: 11
fegiflu is on a distinguished road
umm i don't really understand. do you have a code to show me?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-25-2007, 07:25 PM
Member
 
Join Date: Jul 2007
Posts: 11
fegiflu is on a distinguished road
>.< can anyone help?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-25-2007, 11:25 PM
Member
 
Join Date: Jul 2007
Posts: 11
fegiflu is on a distinguished road
*bump* i really need help with this please
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-26-2007, 07:31 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
You are using arrays. You can not remove an element from an array. You can only change its value.

If you really want to remove an element in an easy way, then use ArrayList or a Vector instead of array. But if you still want to use arrays, you will need to recreate the new array without the element removed as momo97 told.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-26-2007, 07:45 PM
Member
 
Join Date: Jul 2007
Posts: 11
fegiflu is on a distinguished road
>.< how would you that?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-26-2007, 08:19 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Try searching google before asking something!! Once you have some basic knowledge and try some solutions yourself, you can ask your question. In that way, you can learn and also get more answers! Just a suggestion..
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 07-26-2007, 11:58 PM
Member
 
Join Date: Jul 2007
Posts: 8
momo97 is on a distinguished road
burned fegiflu!!, but it's ok, try this:

public void removeElementAt(int removal Index) {
for(int i = removalIndex; i < last; i++)
list[i] = list[i+1];
last--;
}
This shifts all elements up one so when you tell the program to remove an object, it shifts all spots up one so that spot is cleared and thus you have a remove function.
Good Luck!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Averages of user inputed values (Need Help) Zebra New To Java 2 04-16-2008 02:51 PM
image removing Triss New To Java 3 01-20-2008 09:27 PM
Removing characters kDude New To Java 3 12-03-2007 03:38 AM
removing duplicates from arrays bugger New To Java 3 11-13-2007 07:11 PM
Append text inputed in the textfield into a TextArea romina AWT / Swing 1 08-07-2007 06:35 AM


All times are GMT +3. The time now is 09:16 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org