delete replicating values from an array[]....
Question posted by: aswath
(Newbie)
on
March 26th, 2008 01:40 PM
hi dere,
i have a question.
i have an array with replicating values.... al i want to do is
delete all replicating values and store the result in another array.
eg.,
String[] a={1,2,3,3};
String []b;
b should be 1.2.3only........not 1,2,3,3
thanks in advance,
regards,
aswath.n.s
(knowledge is power)
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
|
|
March 26th, 2008 01:43 PM
# 2
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by aswath
hi dere,
i have a question.
i have an array with replicating values.... al i want to do is
delete all replicating values and store the result in another array.
eg.,
String[] a={1,2,3,3};
String []b;
b should be 1.2.3only........not 1,2,3,3
thanks in advance,
regards,
aswath.n.s
(knowledge is power)
|
What is your question?!
regards,
sukatoa
|
|
March 26th, 2008 01:50 PM
# 3
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by aswath
hi dere,
i have a question.
i have an array with replicating values.... al i want to do is
delete all replicating values and store the result in another array.
eg.,
String[] a={1,2,3,3};
String []b;
b should be 1.2.3only........not 1,2,3,3
thanks in advance,
regards,
aswath.n.s
(knowledge is power)
|
... and what have you done so far?
Kind regards
HashSet.
|
|
March 26th, 2008 03:56 PM
# 4
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by aswath
(knowledge is power)
|
I don't think so: knowing what to do with your knowledge may give some power,
otherwise you just have to carry that knowledge around in your brain.
kind regards,
Jos
|
|
March 26th, 2008 04:25 PM
# 5
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by JosAH
I don't think so: knowing what to do with your knowledge may give some power,
otherwise you just have to carry that knowledge around in your brain.
kind regards,
Jos
|
... and to prove that, I wrote some VB.NET code today.(there's a first time for everything).
@Jos surely there's an easier way for that problem?
|
|
March 26th, 2008 05:10 PM
# 6
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by r035198x
... and to prove that, I wrote some VB.NET code today.(there's a first time for everything).
@Jos surely there's an easier way for that problem?
|
Erm, I didn't mean to say that when you accidentally know something that you
*have* to exercise that knowledge. Some knowledge can better be forgotten ;-)
kind regards,
Jos
ps. you can also iterate from the right and stop when you hit a letter ...
|
|
March 26th, 2008 05:18 PM
# 7
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by JosAH
...
ps. you can also iterate from the right and stop when you hit a letter ...
|
Yeah I knew that, I just couldn't grasp the syntax for the for loop!!
*hides in a little corner*
|
|
March 26th, 2008 05:29 PM
# 8
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by r035198x
Yeah I knew that, I just couldn't grasp the syntax for the for loop!!
|
I consider that a little plus on your side.
Quote:
Originally Posted by r035198x
*hides in a little corner*
|
No need to, nobody is perfect. Case closed, this is a Java forum after all.
kind regards,
Jos ( <--- knows nooooothing about Basic ;-)
|
|
March 26th, 2008 06:11 PM
# 9
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by JosAH
I consider that a little plus on your side.
No need to, nobody is perfect. Case closed, this is a Java forum after all.
kind regards,
Jos ( <--- knows nooooothing about Basic ;-)
|
Coming back to the original question then, how would I get this duplicates Snipper to work for primitives as well?
Code: ( text )
import java.util.Arrays; import java.util.Collection; import java.util.HashSet; public class Snipper<E> { E[] array; public static void main(String[] args) { Integer[] x = {4,4,7}; System.out.println(Arrays.toString(new Snipper<Integer>().removeDups(x))); } public E[] removeDups(Object o) { Collection<E> c = null; if(o instanceof Collection) { c = (Collection<E>)o; } else { try { array = (E[])o; } catch(ClassCastException cCE) { System.out.println("Not supported"); } } if(c != null) { HashSet<E> s = new HashSet (c); array = (E[])s.toArray(); } else if(array != null) { final HashSet<E> s = new HashSet () { { for(E e : array) { add(e); } } }; array = (E[])s.toArray(); } return array; } }
|
|
March 27th, 2008 06:42 AM
# 10
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by r035198x
Coming back to the original question then, how would I get this duplicates Snipper to work for primitives as well?
Code: ( text )
import java.util.Arrays; import java.util.Collection; import java.util.HashSet; public class Snipper<E> { E[] array; public static void main(String[] args) { Integer[] x = {4,4,7}; System.out.println(Arrays.toString(new Snipper<Integer>().removeDups(x))); } public E[] removeDups(Object o) { Collection<E> c = null; if(o instanceof Collection) { c = (Collection<E>)o; } else { try { array = (E[])o; } catch(ClassCastException cCE) { System.out.println("Not supported"); } } if(c != null) { HashSet<E> s = new HashSet (c); array = (E[])s.toArray(); } else if(array != null) { final HashSet<E> s = new HashSet () { { for(E e : array) { add(e); } } }; array = (E[])s.toArray(); } return array; } }
|
come on frds.....
i said knowledge is power not MY knowledge is powerful...
n'way lets drop this issue...
hi r035198x ,
i used ur code and its working fine.....
however i would relly appricate if u could explain me that... i hope i'm not bothering u...
regards,
aswath ns
(knowledge is power)
|
|
March 27th, 2008 07:10 AM
# 11
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by lopez
come on frds.....
i said knowledge is power not MY knowledge is powerful...
n'way lets drop this issue...
hi r035198x ,
i used ur code and its working fine.....
however i would relly appricate if u could explain me that... i hope i'm not bothering u...
regards,
aswath ns
(knowledge is power)
|
I didn't think you were going to use it because I thought you had an int[].
Which part do you not understand?
|
|
March 27th, 2008 07:14 AM
# 12
|
Re: delete replicating values from an array[]....
Hey, are you using two accounts?
|
|
March 28th, 2008 04:04 AM
# 13
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by r035198x
Hey, are you using two accounts?
|
she is my college Colleague.. check her mail id if needed frnd.. i posed from her account...
i cannot get u wen u say<E>.. is that some generic terms r wat.. can u plz help me with that.....
regards
|
|
March 28th, 2008 06:25 AM
# 14
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by aswath
she is my college Colleague.. check her mail id if needed frnd.. i posed from her account...
i cannot get u wen u say<E>.. is that some generic terms r wat.. can u plz help me with that.....
regards
|
You can read all about those here.
|
|
March 28th, 2008 09:16 AM
# 15
|
Re: delete replicating values from an array[]....
wat happened to this forum..
why the Admin's are very hard in their words.
please understand the other people those who are starter, freshers to this language and selected this forum for help.
why cant the experienced people know and understand this and reply to your
help needed people.
no one knows fully and no one is unknown here...
please dont use hard words which will make the subscribers not to visit again
this forum helped me so much..
so i wrote this reply.
Even though this is not the JAVA RELATED REPLY.
regards!!!
well wisher
|
|
March 28th, 2008 09:27 AM
# 16
|
Re: delete replicating values from an array[]....
Quote:
Originally Posted by prisesh26
wat happened to this forum..
why the Admin's are very hard in their words.
please understand the other people those who are starter, freshers to this language and selected this forum for help.
why cant the experienced people know and understand this and reply to your
help needed people.
no one knows fully and no one is unknown here...
please dont use hard words which will make the subscribers not to visit again
this forum helped me so much..
so i wrote this reply.
Even though this is not the JAVA RELATED REPLY.
regards!!!
well wisher
|
Feedback related messages should be posted in the feedback forum only. If you feel there is an inappropriate response from an Admin (or moderator) you can post your feelings in that forum, stating the inappropriate response of course.
|
|
March 28th, 2008 09:45 AM
# 17
|
Re: delete replicating values from an array[]....
but it will take time to go through the feed back section in their busy schedule.
so i have written here. any way i will post it FEEDBACK section.
Not the answer you were looking for? Post your question . . .
184,042 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Latest Articles: Read & Comment
Top Java Forum Contributors
|