473,473 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

delete replicating values from an array[]....

18 New Member
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)
Mar 26 '08 #1
16 1924
sukatoa
539 Contributor
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
Mar 26 '08 #2
r035198x
13,262 MVP
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.
Mar 26 '08 #3
JosAH
11,448 Recognized Expert MVP
(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
Mar 26 '08 #4
r035198x
13,262 MVP
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?
Mar 26 '08 #5
JosAH
11,448 Recognized Expert MVP
... 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 ...
Mar 26 '08 #6
r035198x
13,262 MVP
...

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*
Mar 26 '08 #7
JosAH
11,448 Recognized Expert MVP
Yeah I knew that, I just couldn't grasp the syntax for the for loop!!
I consider that a little plus on your side.

*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 ;-)
Mar 26 '08 #8
r035198x
13,262 MVP
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?


Expand|Select|Wrap|Line Numbers
  1. import java.util.Arrays;
  2. import java.util.Collection;
  3. import java.util.HashSet;
  4. public class  Snipper<E> {
  5.     E[] array;
  6.     public static void main(String[] args) {
  7.         Integer[] x = {4,4,7};
  8.         System.out.println(Arrays.toString(new Snipper<Integer>().removeDups(x)));
  9.     }
  10.     public E[] removeDups(Object o) {
  11.         Collection<E> c = null;
  12.  
  13.         if(o instanceof Collection) {
  14.             c = (Collection<E>)o; 
  15.         }
  16.         else {
  17.             try {
  18.                 array = (E[])o;
  19.             }
  20.             catch(ClassCastException cCE) {
  21.                 System.out.println("Not supported");
  22.  
  23.             }
  24.         }
  25.         if(c != null) {
  26.             HashSet<E> s = new HashSet (c);
  27.             array = (E[])s.toArray();
  28.         }
  29.         else if(array != null) {
  30.             final HashSet<E> s = new HashSet () {
  31.                 {
  32.                     for(E e : array) {
  33.                         add(e);
  34.                     }
  35.                 }
  36.             };
  37.             array = (E[])s.toArray();
  38.         }
  39.         return array;
  40.     }
  41. }
Mar 26 '08 #9
lopez
6 New Member
Coming back to the original question then, how would I get this duplicates Snipper to work for primitives as well?


Expand|Select|Wrap|Line Numbers
  1. import java.util.Arrays;
  2. import java.util.Collection;
  3. import java.util.HashSet;
  4. public class  Snipper<E> {
  5.     E[] array;
  6.     public static void main(String[] args) {
  7.         Integer[] x = {4,4,7};
  8.         System.out.println(Arrays.toString(new Snipper<Integer>().removeDups(x)));
  9.     }
  10.     public E[] removeDups(Object o) {
  11.         Collection<E> c = null;
  12.  
  13.         if(o instanceof Collection) {
  14.             c = (Collection<E>)o; 
  15.         }
  16.         else {
  17.             try {
  18.                 array = (E[])o;
  19.             }
  20.             catch(ClassCastException cCE) {
  21.                 System.out.println("Not supported");
  22.  
  23.             }
  24.         }
  25.         if(c != null) {
  26.             HashSet<E> s = new HashSet (c);
  27.             array = (E[])s.toArray();
  28.         }
  29.         else if(array != null) {
  30.             final HashSet<E> s = new HashSet () {
  31.                 {
  32.                     for(E e : array) {
  33.                         add(e);
  34.                     }
  35.                 }
  36.             };
  37.             array = (E[])s.toArray();
  38.         }
  39.         return array;
  40.     }
  41. }


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)
Mar 27 '08 #10
r035198x
13,262 MVP
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?
Mar 27 '08 #11
r035198x
13,262 MVP
Hey, are you using two accounts?
Mar 27 '08 #12
aswath
18 New Member
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
Mar 28 '08 #13
r035198x
13,262 MVP
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.
Mar 28 '08 #14
prisesh26
29 New Member
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
Mar 28 '08 #15
r035198x
13,262 MVP
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.
Mar 28 '08 #16
prisesh26
29 New Member
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.
Mar 28 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
30
by: jimjim | last post by:
Hello, This is a simple question for you all, I guess . int main(){ double *g= new double; *g = 9; delete g; cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl; *g =...
1
by: JasonK | last post by:
I would like to move the Delete button such that it displays one time in the footer row, rather than on every row. I've seen lots of questions asked on the subject around the net, but no answer...
1
by: flash | last post by:
Need hlep to delete array only because all function is ok (inser, sort andsearch) #include <iostream.h> //functions prototype void Insert(int,int); void Delete(int,int); int...
29
by: Jon Slaughter | last post by:
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to...
29
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I remembered delete is implemented through operator overloading, but I am not quite clear. Could anyone recommend some links about how delete is implemented so that I can...
12
by: subramanian100in | last post by:
Suppose class Base { public: virtual ~Test() { ... } // ... }; class Derived : public Base
9
by: Oliver Graeser | last post by:
Hi All, I do some ensemble averaging calculation that requires me to accumulate very many distributions which I store in arrays. Basically something like class AdaptiveNW{ public: int**...
5
dlite922
by: dlite922 | last post by:
I can't believe I haven't come across this in all of my PHP programming (or my brain is currently locked)...I need to delete an array from an array that i'm traversing through with a foreach. ...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.