Results 1 to 9 of 9
- 07-24-2007, 06:38 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 11
- Rep Power
- 0
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 )
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]);
}
}
- 07-24-2007, 06:44 PM #2
Member
- Join Date
- Jul 2007
- Posts
- 8
- Rep Power
- 0
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.
- 07-24-2007, 09:01 PM #3
Member
- Join Date
- Jul 2007
- Posts
- 11
- Rep Power
- 0
umm i don't really understand. do you have a code to show me?
- 07-25-2007, 06:25 PM #4
Member
- Join Date
- Jul 2007
- Posts
- 11
- Rep Power
- 0
>.< can anyone help?
- 07-25-2007, 10:25 PM #5
Member
- Join Date
- Jul 2007
- Posts
- 11
- Rep Power
- 0
*bump* i really need help with this please
- 07-26-2007, 06:31 PM #6levent Guest
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.
- 07-26-2007, 06:45 PM #7
Member
- Join Date
- Jul 2007
- Posts
- 11
- Rep Power
- 0
>.< how would you that?
- 07-26-2007, 07:19 PM #8levent Guest
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..
- 07-26-2007, 10:58 PM #9
Member
- Join Date
- Jul 2007
- Posts
- 8
- Rep Power
- 0
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!
Similar Threads
-
Averages of user inputed values (Need Help)
By Zebra in forum New To JavaReplies: 2Last Post: 04-16-2008, 01:51 PM -
image removing
By Triss in forum New To JavaReplies: 3Last Post: 01-20-2008, 08:27 PM -
Removing characters
By kDude in forum New To JavaReplies: 3Last Post: 12-03-2007, 02:38 AM -
removing duplicates from arrays
By bugger in forum New To JavaReplies: 3Last Post: 11-13-2007, 06:11 PM -
Append text inputed in the textfield into a TextArea
By romina in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 05:35 AM
Bookmarks