• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

String / float Question

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String str = "Amardeep";
String stra = new String("Amardeep);
or
String strb = new String();

Is String is A primitive or wrapper class ?

Similarly

float flt =10.08f;
Float flt = new Float();
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amardeep Salkar:
String str = "Amardeep";
String stra = new String("Amardeep);
or
String strb = new String();

Is String is A primitive or wrapper class ?

Similarly

float flt =10.08f;
Float flt = new Float();



Neither is String a primitive nor a wrapper. It is a general class in java.util package which is used to work on string like char[] in C++(although char[] of C++ and String of Java are way different).

Float is a wrapper class...also Float constructor must be provided a double, float or String value.
 
Amardeep Salkar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As i know float is a primitive and double is a wrapper class

because primitive type of double is float. but what about Float

i.e
float ft = 10.64f
Float flt = new Float(ft);
or
Float flt = new Float();

Reply me if I'm wrong...
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

As i know float is a primitive and double is a wrapper class



You are wrong. Both float and double are primitive.

type of double is float



Again Wrong...double and float are two separate primitive types.

what about Float



Well every primitive type has a corresponding Wrapper class..this is a list of primitive types and their corresponding wrapper classes.

+-----------+---------+
| primitive | wrapper |
+-----------+---------+
| boolean | Boolean |
| byte | Byte |
| short | Short |
| char |Character|
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
+-----------+---------+
[ August 08, 2008: Message edited by: Ankit Garg ]
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amardeep, check out: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html . You will find some useful basic information on primitives that should help you undertsand the topic better. Regards
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic